leocolomb/wp-redis

A persistent cache backend for WordPress powered by Redis.

3.2.1 2022-07-25 14:00 UTC

This package is auto-updated.

Last update: 2024-10-09 23:24:59 UTC


README

A persistent cache backend powered by Redis.

Build Status Packagist

Features

  • Enables the two cache wrappers for WordPress
  • 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