Description
Pour les sites à trafic élevé, nécessitant de la rapidité pour les utilisateurs connectés ou des chargements de pages dynamiques, un cache d‘objet à haute vitesse et persistant est indispensable. Vous avez également besoin d‘une solution qui peut s‘adapter à plusieurs instances de votre application, ce qui exclut l‘utilisation de caches de fichiers locaux ou d‘APC.
Redis is a great answer, and one we bundle on the Pantheon platform. This is our plugin for integrating with the cache, but you can use it on any self-hosted WordPress site if you have Redis. Install from WordPress.org or Github.
Il est important de noter qu‘un cache d‘objet persistant n‘est pas une solution miracle – un chargement de page avec 2 000 appels Redis peut représenter 2 secondes complètes de transactions de cache d‘objet. Assurez-vous d‘utiliser le cache d‘objet de manière judicieuse : limitez-vous à un nombre raisonnable de clés, n‘enregistrez pas une quantité énorme de données sur chaque clé et évitez les écritures et les suppressions simultanées au niveau de l‘interface publique.
Allez de l‘avant et créez quelque chose d‘extraordinaire ! Et une fois que vous aurez construit quelque chose de génial, envoyez-nous vos demandes de fonctionnalités (ou rapports de bogues). Jetez un coup d‘œil au wiki pour des extraits de code utiles et d‘autres astuces.
Commandes WP-CLI
This plugin implements a variety of WP-CLI commands. All commands are grouped into the wp redis namespace.
$ wp help redis
NAME
wp redis
SYNOPSIS
wp redis <command>
SUBCOMMANDS
cli Launch redis-cli using Redis configuration for WordPress
debug Debug object cache hit / miss ratio for any page URL.
enable Enable WP Redis by creating the symlink for object-cache.php
info Provide details on the Redis connection.
Utilisez wp help redis <commande> pour en savoir plus sur chaque commande.
Contribution
Voir CONTRIBUTING.md pour les informations de contribution.
Installation
This assumes you have a PHP environment with the required PhpRedis extension and a working Redis server (e.g. Pantheon). WP Redis also works with Predis via humanmade/wp-redis-predis-client.
- Installez
object-cache.phpà la place dewp-content/object-cache.phpavec un lien symbolique ou en recopiant le fichier. -
Si vous n‘êtes pas sous Pantheon, modifiez wp-config.php pour ajouter les informations relatives à la gestion de votre cache, par exemple :
$redis_server = array( 'host' => '127.0.0.1', 'port' => 6379, 'auth' => '12345', // ['user', 'password'] if you use Redis ACL 'database' => 0, // Optionally use a specific numeric Redis database. Default is 0. ); -
If your Redis server is listening through a socket file instead, set its path on
hostparameter and change the port tonull:$redis_server = array( 'host' => '/path/of/redis/socket-file.sock', 'port' => null, 'auth' => '12345', 'database' => 0, // Optionally use a specific numeric Redis database. Default is 0. ); -
Mettez les propulseurs en marche : vous utilisez désormais Redis pour sauvegarder le cache d‘objet de WP.
- (Facultatif) Pour utiliser les commandes WP-CLI
wp redis, activez l‘extensions WP Redis. Aucune activation n‘est nécessaire si vous utilisez uniquement le remplacement de cache d‘objet. - (Optional) To use the same Redis server with multiple, discreet WordPress installs, you can use the
WP_CACHE_KEY_SALTconstant to define a unique salt for each install. - (Facultatif) Pour utiliser de véritables groupes de cache, avec la possibilité de supprimer toutes les clés d‘un groupe donné, enregistrez les groupes avec la fonction
wp_cache_add_redis_hash_groups()ou définissez la constanteWP_REDIS_USE_CACHE_GROUPSsurtruepour activer tous les groupes. Cependant, lorsqu‘elle est activée, la valeur d‘expiration n‘est pas respectée car l‘expiration des clés de groupe n‘est pas une fonctionnalité prise en charge par Redis. - (Facultatif) Sur un site existant qui utilisait auparavant le cache transitoire de WordPress, utilisez WP-CLI pour supprimer tous les transients (
%transient%) de la table des options :wp transient delete-all. WP Redis assume la responsabilité du cache transitoire. - (Facultatif) Pour utiliser Relay à la place de PHP Redis en tant que client, définir la constante
WP_REDIS_USE_RELAYàtrue. Pour les demandes d‘assistance, merci de passer par les discussions GitHub de Relay.
FAQ
-
Pourquoi voudrais-je utiliser cette extension ?
-
If you are concerned with the speed of your site, backing it with a high-performance, persistent object cache can have a huge impact. It takes load off your database, and is faster for loading all the data objects WordPress needs to run.
-
Comment fonctionne WP Redis avec d‘autres extensions de cache ?
-
This plugin is for the internal application object cache. It doesn’t have anything to do with page caches. On Pantheon you do not need additional page caching, but if you are self-hosted you can use your favorite page cache plugins in conjunction with WP Redis.
-
Comment puis-je désactiver la persistance du cache objet d‘un mauvais acteur ?
-
A page load with 2,000 Redis calls can be 2 full seconds of object cache transactions. If a plugin you’re using is erroneously creating a huge number of cache keys, you might be able to mitigate the problem by disabling cache persistency for the plugin’s group:
wp_cache_add_non_persistent_groups( array( 'bad-actor' ) );Cette déclaration signifie que l‘utilisation de
wp_cache_set( 'foo', 'bar', 'bad-actor' );etwp_cache_get( 'foo', 'bad-actor' );n‘utilisera pas Redis, mais fera plutôt appel au cache d‘objet en temps d‘exécution par défaut de WordPress. -
Pourquoi le cache d‘objet se désynchronise-t-il parfois avec la base de données ?
-
Il existe un problème connu avec la conception du cache
alloptionsde WordPress. Plus précisément, une condition de concurrence entre deux requêtes peut entraîner des valeurs obsolètes dans le cache d‘objet. Si vous pensez être concerné par ce problème, veuillez consulter cette question sur GitHub pour obtenir plus de détails, y compris une solution de contournement. -
Where do I report security bugs found in this plugin?
-
Please report security bugs found in the source code of the WP Redis plugin through the Patchstack Vulnerability Disclosure Program. The Patchstack team will assist you with verification, CVE assignment, and notify the developers of this plugin.
Avis
Contributeurs/contributrices & développeurs/développeuses
« WP Redis » est un logiciel libre. Les personnes suivantes ont contribué à cette extension.
ContributeursTraduisez « WP Redis » dans votre langue.
Le développement vous intéresse ?
Parcourir le code, consulter le SVN dépôt, ou s’inscrire au journal de développement par RSS.
Journal des modifications
1.4.7 (December 2, 2025)
- WordPress 6.9 compatibility [#524]
1.4.6 (June 17, 2025)
- PHP 8.4 compatibility
1.4.5 (January 21, 2024)
- Support Relay in check_client_dependencies() with the WP_REDIS_USE_RELAY constant [#471]
1.4.4 (November 27, 2023)
- Updates Pantheon WP Coding Standards to 2.0 [#445]
- Handle duplicate keys in
get_multiplefunction [#448] (props @souptik)
1.4.3 (June 26, 2023)
- Bug fix: Fixes assumption that CACHE_PORT & CACHE_PASSWORD are Set. [428] (props @tnolte)
- Adds WP.org validation GitHub action [#435]
- Bug fix: Fixes incorrect order of
array_replace_recursiveand other issues [434] (props @timnolte) - Bug fix: Replace use of wp_strip_all_tags in object-cache.php [434] (props @timnolte)
- Bug fix: Don’t strip tags from the cache password. [434] (props @timnolte)
1.4.2 (May 15, 2023)
- Bug fix: Removes exception loop caused by
esc_htmlin_exception_handler()[421]
1.4.1 (May 11, 2023)
- Bug fix:
wp_cache_flush_runtimeshould only clear the local cache [413]
1.4.0 (May 9, 2023)
- Add support for
flush_runtimeandflush_groupfunctions [#405] - Add
pantheon-wp-coding-standards[#400] - Update CONTRIBUTING.MD [#406]
- Update Composer dependencies [#401]
1.3.5 (April 6, 2023)
- Bump tested up to version to 6.2
- Update Composer dependencies [#394]
1.3.4 (March 7, 2023)
- Set
missing_redis_messageif Redis service is not connected [#391].
1.3.3 (February 28, 2023)
- Add PHP 8.2 support [#388].
- Remove Grunt, add valid license to Composer file [#387].
- Update Composer dependencies [#384] [#385].
1.3.2 (December 5, 2022)
- Fix broken
wp_cache_supportsfunction [#382].
1.3.1 (December 2, 2022)
- Declare
wp_cache_supportsfunction and support features. [#378] - Make dependabot target
developbranch for PRs. [#376]
1.3.0 (November 29, 2022)
- Added CONTRIBUTING.MD and GitHub action to automate deployments to wp.org. [#368]
1.2.0 (February 17, 2022)
- Adds support for Relay via
WP_REDIS_USE_RELAYconstant [#344].
1.1.4 (October 21, 2021)
- Fixes some faulty logic in
WP_REDIS_IGNORE_GLOBAL_GROUPScheck [#333].
1.1.3 (October 21, 2021)
- Supports a
WP_REDIS_IGNORE_GLOBAL_GROUPSconstant to prevent groups from being added to global caching group [#331].
1.1.2 (March 24, 2021)
- Applies logic used elsewhere to fall back to
$_SERVERinwp_redis_get_info()[#316].
1.1.1 (August 17, 2020)
- Returns cache data in correct order when using
wp_cache_get_multiple()and internal cache is already primed [#292].
1.1.0 (July 13, 2020)
- Implements
wp_cache_get_multiple()for WordPress 5.5 [#287]. - Bails early when connecting to Redis throws an Exception to avoid fatal error [285].
1.0.1 (April 14, 2020)
- Adds support for specifying Redis database number from environment/server variables [#273].
1.0.0 (March 2, 2020)
- Plugin is stable.
0.8.3 (February 24, 2020)
- Fixes
wp redis cliby usingproc_open()directly, instead ofWP_CLI::launch()[#268].
0.8.2 (January 15, 2020)
- Catches exceptions when trying to connect to Redis [#265].
0.8.1 (January 10, 2020)
- Adds
WP_REDIS_DEFAULT_EXPIRE_SECONDSconstant to set default cache expire value [#264].
0.8.0 (January 6, 2020)
- Uses
flushdbinstead offlushAllto avoid flushing the entire Redis instance [#259].
0.7.1 (December 14, 2018)
- Better support in
wp_cache_init()for drop-ins like LudicrousDB [#231]. - Cleans up PHPCS issues.
0.7.0 (August 22, 2017)
- Adds filterable connection methods to permit use of Predis. See humanmade/wp-redis-predis-client for more details.
0.6.2 (June 5, 2017)
- Bug fix: Preserves null values in internal cache.
- Bug fix: Converts numeric values to their true type when getting.
0.6.1 (February 23, 2017)
- Bug fix: correctly passes an empty password to
redis-cli. - Variety of improvements to the test suite.
0.6.0 (September 21, 2016)
- Introduces three new WP-CLI commands:
wp redis debugto display cache hit/miss ratio for any URL;wp redis infoto display high-level Redis statistics;wp redis enableto create theobject-cache.phpsymlink. - Permits a Redis database to be defined with
$redis_server['database']. - Introduces
wp_cache_add_redis_hash_groups(), which permits registering specific groups to use Redis hashes, and is more precise than our existingWP_REDIS_USE_CACHE_GROUPSconstant.
0.5.0 (April 27, 2016)
- Performance boost! Removes redundant
existscall fromwp_cache_get(), which easily halves the number of Redis calls. - Uses
add_action()and$wpdbin a safer manner for compatibility with Batcache, which loads the object cache before aforementioned APIs are available. - For debugging purposes, tracks number of calls to Redis, and includes breakdown of call types.
- Adds a slew of more explicit test coverage against existing features.
- For consistency with the actual Redis call, calls
delinstead ofdelete. - Bug fix: If a group isn’t persistent, don’t ever make an
existscall against Redis.
0.4.0 (March 23, 2016)
- Introduces
wp redis-cli, a WP-CLI command to launch redis-cli with WordPress’ Redis credentials. - Bug fix: Ensures fail back mechanism works as expected on multisite, by writing to sitemeta table instead of the active site’s options table.
- Bug fix: Uses ‘default’ as the default cache group, mirroring WordPress core, such that
$wp_object_cache->add( 'foo', 'bar' )===wp_cache_add( 'foo', 'bar' ).
0.3.0 (February 11, 2016)
- Introduces opt-in support for Redis cache groups. Enable with
define( 'WP_REDIS_USE_CACHE_GROUPS', true );. When enabled, WP Redis persists cache groups in a structured manner, instead of hashing the cache key and group together. - Uses PHP_CodeSniffer and WordPress Coding Standards sniffs to ensure WP Redis adheres to WordPress coding standards.
- Bug fix: Permits use of a Unix socket in
$redis_server['host']by ensuring the supplied$portis null.
0.2.2 (November 24, 2015)
- Bug fix: use
INSERT IGNORE INTOinstead ofINSERT INTOto prevent SQL errors when two concurrent processes attempt to write failback flag at the same time. - Bug fix: use
E_USER_WARNINGwithtrigger_error(). - Bug fix: catch Exceptions thrown during authentication to permit failing back to internal object cache.
0.2.1 (November 17, 2015)
- Bug fix: prevent SQL error when
$wpdb->optionsisn’t yet initialized on multisite.
0.2.0 (November 17, 2015)
- Gracefully fails back to the WordPress object cache when Redis is unavailable or intermittent. Previously, WP Redis would hard fatal.
- Triggers a PHP error if Redis goes away mid-request, for you to monitor in your logs. Attempts one reconnect based on specific error messages.
- Forces a flushAll on Redis when Redis comes back after failing. This behavior can be disabled with the
WP_REDIS_DISABLE_FAILBACK_FLUSHconstant. - Show an admin notice when Redis is unavailable but is expected to be.
0.1
- Initial commit of working code for the benefit of all.
