Redis Object Cache Plugin
Redis Object Cache is a WordPress plugin that provides a persistent, Redis-based backend for the WordPress object cache. Use it if you want to speed up your site and prefer Redis to other key-value stores.
Fair warning: If you’re not sure what Redis is and are just looking for ways to improve your site’s performance, you’ll probably be better off using a more conventional solution like W3 Total Cache + Memcached. This plugin is primarily for people who love Redis (like me :-)) or want to learn more about WordPress object cache.
Click a screenshot to view full size.
redis-cache.zip (35 KB)
- WordPress 3.2+
- PHP 5.2.6+
- A working Redis server.
You can use Debug Bar to view cache statistics like cache hits/misses, used memory and so on.
If you intend to use one Redis server both for WordPress caching and something else, make sure to change the “Redis database index” setting to a different value. The plugin will automatically flush the specified database upon activation, which can result in a nasty surprise if you happen to have important data stored there. So if your other project(s) use database #1, set Redis Object Cache to use database #2 instead.
It is also worth mentioning that, when using this plugin, certain object cache functions will work slightly differently than if you were using a Memcached backend. Here’s a list:
- wp_cache_replace is not atomic. wp_cache_add is only atomic if $expire is zero.
- wp_cache_decr can cause a value to become negative.
- Increment/decrement operations on non-existent keys always succeed and set the key to the specified $offset value.
All of these are due to subtle differences in how Redis and Memcached implement (or don’t implement) the same features. Technically, you could work around them by using Redis transactions, but I didn’t want to mess with that for a simple project like this.Related posts :
Very cool! How would you compare the performance benefit of this to other object caches?
I have not tested it, but I expect the performance would be similar to object caches based on Memcached or other in-memory caching systems.
[…] The codes in this plug-in shows how to use predis in action within WP: http://w-shadow.com/blog/2012/05/24/redis-object-cache-plugin/ (2) login/logout Supported and customizable (it’s even “pluggable” !!! ). […]