Contributors: getpantheon, danielbachhuber, mboynes, Outlandish Josh
Tags: cache, plugin
Requires at least: 3.0.1
Tested up to: 4.5
Stable tag: 0.4.0
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Back your WP Object Cache with Redis, a high-performance in-memory storage backend.
For sites concerned with high traffic, speed for logged-in users, or dynamic pageloads, a high-speed and persistent object cache is a must. You also need something that can scale across multiple instances of your application, so using local file caches or APC are out.
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.
Go forth and make awesome! And, once you've built something great, send us feature requests (or bug reports).
This assumes you have a PHP environment with the required PhpRedis extension and a working Redis server (e.g. Pantheon).
-
Install
object-cache.php
towp-content/object-cache.php
with a symlink or by copying the file. -
If you're not running on Pantheon, edit wp-config.php to add your cache credentials, e.g.:
$redis_server = array( 'host' => '127.0.0.1', 'port' => 6379, 'auth' => '12345', );
-
Engage thrusters: you are now backing WP's Object Cache with Redis.
-
(Optional) To use the same Redis server with multiple, discreet WordPress installs, you can use the
WP_CACHE_KEY_SALT
constant to define a unique salt for each install. -
(Optional) To use true cache groups, with the ability to delete all keys for a given group, define the
WP_REDIS_USE_CACHE_GROUPS
constant to true. However, when enabled, the expiration value is not respected because expiration on group keys isn't a feature supported by Redis. -
(Optional) On an existing site previously using WordPress' transient cache, use WP-CLI to delete all (
%_transient_%
) transients from the options table:wp transient delete-all
. WP Redis assumes responsibility for the transient cache.
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.
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.
The best way to contribute to the development of this plugin is by participating on the GitHub project:
https://github.com/pantheon-systems/wp-redis
Pull requests and issues are welcome!
- 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' )
.
- 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$port
is null.
- Bug fix: use
INSERT IGNORE INTO
instead ofINSERT INTO
to prevent SQL errors when two concurrent processes attempt to write failback flag at the same time. - Bug fix: use
E_USER_WARNING
withtrigger_error()
. - Bug fix: catch Exceptions thrown during authentication to permit failing back to internal object cache.
- Bug fix: prevent SQL error when
$wpdb->options
isn't yet initialized on multisite.
- 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_FLUSH
constant. - Show an admin notice when Redis is unavailable but is expected to be.
- Initial commit of working code for the benefit of all.