Description
A persistent object cache backend powered by Redis. Supports Predis, PhpRedis (PECL), HHVM, replication, clustering and WP-CLI.
To adjust the connection parameters, prefix cache keys or configure replication/clustering, please see Other Notes.
Forked from Eric Mann’s and Erick Hitter’s Redis Object Cache.
Connection Parameters
By default the object cache drop-in will connect to Redis over TCP at 127.0.0.1:6379 and select database 0.
To adjust the connection parameters, define any of the following constants in your wp-config.php file.
-
WP_REDIS_CLIENT(default: not set)Specifies the client used to communicate with Redis. Supports
hhvm,peclandpredis. -
WP_REDIS_SCHEME(default:tcp)Specifies the protocol used to communicate with an instance of Redis. Internally the client uses the connection class associated to the specified connection scheme. Supports
tcp(TCP/IP),unix(UNIX domain sockets),tls(transport layer security) orhttp(HTTP protocol through Webdis). -
WP_REDIS_HOST(default:127.0.0.1)IP or hostname of the target server. This is ignored when connecting to Redis using UNIX domain sockets.
-
WP_REDIS_PORT(default:6379)TCP/IP port of the target server. This is ignored when connecting to Redis using UNIX domain sockets.
-
WP_REDIS_PATH(default: not set)Path of the UNIX domain socket file used when connecting to Redis using UNIX domain sockets.
-
WP_REDIS_DATABASE(default:0)Accepts a numeric value that is used to automatically select a logical database with the
SELECTcommand. -
WP_REDIS_PASSWORD(default: not set)Accepts a value used to authenticate with a Redis server protected by password with the
AUTHcommand.Configuration Parameters
To adjust the configuration, define any of the following constants in your
wp-config.phpfile. -
WP_CACHE_KEY_SALT(default: not set)Set the prefix for all cache keys. Useful in setups where multiple installs share a common
wp-config.phpor$table_prefixto guarantee uniqueness of cache keys. -
WP_REDIS_SELECTIVE_FLUSH(default: not set)If set to
true, flushing the cache will only delete keys that are prefixed withWP_CACHE_KEY_SALT(instead of emptying the entire Redis database). The selective flush is an atomicO(n)operation. -
WP_REDIS_MAXTTL(default: not set)Set maximum time-to-live (in seconds) for cache keys with an expiration time of
0. -
WP_REDIS_GLOBAL_GROUPS(default:['blog-details', 'blog-id-cache', 'blog-lookup', 'global-posts', 'networks', 'rss', 'sites', 'site-details', 'site-lookup', 'site-options', 'site-transient', 'users', 'useremail', 'userlogins', 'usermeta', 'user_meta', 'userslugs'])Set the list of network-wide cache groups that should not be prefixed with the blog-id (Multisite only).
-
WP_REDIS_IGNORED_GROUPS(default:['counts', 'plugins'])Set the cache groups that should not be cached in Redis.
-
WP_REDIS_DISABLED(default: not set)Set to
trueto disable the object cache at runtime.Replication & Clustering
To use Replication, Sharding or Clustering, make sure your server is running PHP7 or higher (HHVM is not supported) and you consulted the Predis or PhpRedis documentation.
For replication use the WP_REDIS_SERVERS constant, for sharding the WP_REDIS_SHARDS constant and for clustering the WP_REDIS_CLUSTER constant.
For authentication use the WP_REDIS_PASSWORD constant.
Replication (Master-Slave):
define( 'WP_REDIS_SERVERS', [
'tcp://127.0.0.1:6379?database=5&alias=master',
'tcp://127.0.0.2:6379?database=5&alias=slave-01',
] );
Replication (Redis Sentinel):
define( 'WP_REDIS_CLIENT', 'predis' );
define( 'WP_REDIS_SENTINEL', 'mymaster' );
define( 'WP_REDIS_SERVERS', [
'tcp://127.0.0.1:5380',
'tcp://127.0.0.2:5381',
'tcp://127.0.0.3:5382',
] );
Sharding:
define( 'WP_REDIS_SHARDS', [
'tcp://127.0.0.1:6379?database=10&alias=shard-01',
'tcp://127.0.0.2:6379?database=10&alias=shard-02',
'tcp://127.0.0.3:6379?database=10&alias=shard-03',
] );
Clustering (Redis 3.0+):
define( 'WP_REDIS_CLUSTER', [
'tcp://127.0.0.1:6379?database=15&alias=node-01',
'tcp://127.0.0.2:6379?database=15&alias=node-02',
] );<h3>WP-CLI Commands</h3>
To use the WP-CLI commands, make sure the plugin is activated:
wp plugin activate redis-cache
The following commands are supported:
-
wp redis statusShow the Redis object cache status and (when possible) client.
-
wp redis enableEnables the Redis object cache. Default behavior is to create the object cache drop-in, unless an unknown object cache drop-in is present.
-
wp redis disableDisables the Redis object cache. Default behavior is to delete the object cache drop-in, unless an unknown object cache drop-in is present.
-
wp redis update-dropinUpdates the Redis object cache drop-in. Default behavior is to overwrite any existing object cache drop-in.
Screenshots
Installation
For detailed installation instructions, please read the standard installation procedure for WordPress plugins.
- Make sure Redis is installed and running.
- Install and activate plugin.
- Enable the object cache under Settings -> Redis, or in Multisite setups under Network Admin -> Settings -> Redis.
- If necessary, adjust connection parameters.
If your server doesn’t support the WordPress Filesystem API, you have to manually copy the object-cache.php file from the /plugins/redis-cache/includes/ directory to the /wp-content/ directory.
FAQ
- Installation Instructions
-
For detailed installation instructions, please read the standard installation procedure for WordPress plugins.
- Make sure Redis is installed and running.
- Install and activate plugin.
- Enable the object cache under Settings -> Redis, or in Multisite setups under Network Admin -> Settings -> Redis.
- If necessary, adjust connection parameters.
If your server doesn’t support the WordPress Filesystem API, you have to manually copy the
object-cache.phpfile from the/plugins/redis-cache/includes/directory to the/wp-content/directory.
Reviews
Work Like a Charm on WP FEMP
Moving from Cache Enabler (page cache). Work like a charm on FEMP (FreeBSD 11.2-RELEASE, Nginx 1.15.2, MariaDB 10.2.16, and PHP 7.2.7). And also, I’m connecting this plugin to Redis through Unix Sockets which fully supported. Great job!
Easy to implement
Awesome. Simplified the efforts to enable caching with redis.
Works right out of the box
This plugin worked right out of the box, however this just scratches the surface of all the cool stuff I can do from here using this plugin. Great job!
Awesome
No clutter, it just works™
Awesome job, thanks to the developers!
Redirecting to someone else’s site
After activation plugin and pressing button “Enable Objective Cache” plugin makes redirecting to someone else’s site, after deleting created cache file the problem disappears. It seems to me that the plugin is hacked.
Works with Azure VM and Azure Redis
Works with Azure VM and Azure Redis
Contributors & Developers
“Redis Object Cache” is open source software. The following people have contributed to this plugin.
Contributors“Redis Object Cache” has been translated into 3 locales. Thank you to the translators for their contributions.
Translate “Redis Object Cache” into your language.
Interested in development?
Browse the code, check out the SVN repository, or subscribe to the development log by RSS.
Changelog
1.3.8
- Switched from single file Predis version to full library
1.3.7
- Revert back to single file Predis version
1.3.6
- Added support for Redis Sentinel
- Added support for sharing
- Switched to PHAR version of Predis
- Improved diagnostics
- Added
WP_REDIS_SELECTIVE_FLUSH - Added
$fail_gracefullyparameter toWP_Object_Cache::__construct() - Always enforce
WP_REDIS_MAXTTL - Pass
$selectiveand$salttoredis_object_cache_flushaction - Don’t set
WP_CACHE_KEY_SALTconstant
1.3.5
- Added basic diagnostics to admin interface
- Added
WP_REDIS_DISABLEDconstant to disable cache at runtime - Prevent “Invalid plugin header” error
- Return integer from
increment()anddecrement()methods - Prevent object cache from being instantiated more than once
- Always separate cache key
prefixandgroupby semicolon - Improved performance of
build_key() - Only apply
redis_object_cache_getfilter if callbacks have been registered - Fixed
add_or_replace()to only set cache key if it doesn’t exist - Added
redis_object_cache_flushaction - Added
redis_object_cache_enableaction - Added
redis_object_cache_disableaction - Added
redis_object_cache_update_dropinaction
1.3.4
- Added WP-CLI support
- Show host and port unless scheme is unix
- Updated default global and ignored groups
- Do a cache flush when activating, deactivating and uninstalling
1.3.3
- Updated Predis to
v1.1.1 - Added
redis_instance()method - Added
incr()method alias for Batcache compatibility - Added
WP_REDIS_GLOBAL_GROUPSandWP_REDIS_IGNORED_GROUPSconstant - Added
redis_object_cache_deleteaction - Use
WP_PLUGIN_DIRwithWP_CONTENT_DIRas fallback - Set password when using a cluster or replication
- Show Redis client in
stats() - Change visibility of
$cacheto public - Use old array syntax, just in case
1.3.2
- Make sure
$resultis notfalseinWP_Object_Cache::get()
1.3.1
- Fixed connection issue
1.3
- New admin interface
- Added support for
wp_cache_get()‘s$forceand$foundparameter - Added support for clustering and replication with Predis
1.2.3
- UI improvements
1.2.2
- Added
redis_object_cache_setaction - Added
redis_object_cache_getaction and filter - Prevented duplicated admin status messages
- Load bundled Predis library only if necessary
- Load bundled Predis library using
WP_CONTENT_DIRconstant - Updated
stats()method output to be uniform with WordPress
1.2.1
- Added
composer.json - Added deactivation and uninstall hooks to delete
object-cache.php - Added local serialization functions for better
advanced-cache.phpsupport - Updated bundled Predis version to
1.0.3 - Updated heading structure to be semantic
1.2
- Added Multisite support
- Moved admin menu under Settings menu
- Fixed PHP notice in
get_redis_client_name()
1.1.1
- Call
select()and optionallyauth()if HHVM extension is used
1.1
- Added support for HHVM’s Redis extension
- Added support for PECL Redis extension
- Added
WP_REDIS_CLIENTconstant, to set preferred Redis client - Added
WP_REDIS_MAXTTLconstant, to force expiration of cache keys - Improved
add_or_replace(),get(),set()anddelete()methods - Improved admin screen styles
- Removed all internationalization/localization from drop-in
1.0.2
- Added “Flush Cache” button
- Added support for UNIX domain sockets
- Improved cache object retrieval performance significantly
- Updated bundled Predis library to version
1.0.1
1.0.1
- Load plugin translations
- Hide global admin notices from non-admin users
- Prevent direct file access to
redis-cache.phpandadmin-page.php - Colorize “Disable Object Cache” button
- Call
Predis\Client->connect()to avoid potential uncaughtPredis\Connection\ConnectionException
1.0
- Initial release

