leocolomb / wp-redis
A persistent cache backend for WordPress powered by Redis.
Installs: 7 189
Dependents: 0
Suggesters: 0
Security: 0
Stars: 15
Watchers: 5
Forks: 3
Open Issues: 0
Requires
- php: >=7.1
- koodimonni/composer-dropin-installer: ^1.2
Requires (Dev)
Suggests
- ext-redis: Using a native-Redis interface
- predis/predis: Using a PHP-Redis interface
README
A persistent cache backend powered by Redis.
Features
- Enables the two cache wrappers for WordPress
- Object Cache (
object-cache.php
) - Advanced Page Cache (
advanced-cache.php
)
- Object Cache (
- Adds handy WP-CLI commands
wp redis status
: Show the Redis cache status and (when possible) client.wp redis flush
: Flush the Redis cache, clear all data.
- Supports major PHP Redis drivers
- Supports replication and clustering
- Targets modern software stacks
Installation
-
Prepare your Composer file by adding custom paths (more info)
{ "extra": { "dropin-paths": { "htdocs/wp-content/": [ "package:leocolomb/wp-redis:dropins/object-cache.php", "package:leocolomb/wp-redis:dropins/advanced-cache.php" ] } } }
-
Require the package in your Composer-managed WordPress instance
$ composer require leocolomb/wp-redis
Configuration
To adjust the configuration, define any of the following constants in your wp-config.php
file.
Connection
By default the object cache drop-in will connect to Redis over TCP at 127.0.0.1:6379
and select database 0
.
Parameters
Page cache
Replication & Clustering
To use Replication and Clustering, make sure your server is running PHP7, your setup is using Predis to connect to Redis and you consulted the Predis documentation.
For replication use the WP_REDIS_SERVERS
constant and for clustering the WP_REDIS_CLUSTER
constant. You can use a named array or an URI string to specify the parameters.
For authentication use the WP_REDIS_PASSWORD
constant.
Master-Slave Replication
define('WP_REDIS_SERVERS', [ 'tcp://127.0.0.1:6379?database=15&alias=master', 'tcp://127.0.0.2:6379?database=15&alias=slave-01', ]);
Clustering via Client-side Sharding
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', ]);
License
GPL-3.0 © Léo Colombaro
- Eric Mann and Erick Hitter for Redis Object Cache
- Till Krüss for tillkruss/redis-cache