Configuration

The configuration of Object Cache Pro is done using the WP_REDIS_CONFIG PHP constant in your wp-config.php file.

Any configuration error will generate an error log entry, and if WP_DEBUG is enabled, additionally throw an exception.

The full list of available configuration options can be found in the options guide.

For most production environments the configuration below is a good starting point:

define('WP_REDIS_CONFIG', [
    'token' => '<your-license-token>',
    'host' => '127.0.0.1',
    'port' => 6379,
    'database' => 0, // change for each site
    'maxttl' => 3600 * 24 * 7, // 7 days
    'timeout' => 1.0,
    'read_timeout' => 1.0,
    'prefetch' => true,
    'split_alloptions' => true,
    'strict' => true,
    'debug' => false,
]);

define('WP_REDIS_DISABLED', false);

High Performance

When optimizing high-traffic sites for milliseconds, the configuration below is recommended as well as setting an Eviction Policy.

This configuration requires Redis Server 4.0 (or newer) as well as PhpRedis to be compiled with igbinary and zstd support.

Be sure to read about data encoding to avoid crashing your site when using this configuration.

define('WP_REDIS_CONFIG', [
    'token' => '...',
    'host' => '127.0.0.1',
    'port' => 6379,
    'database' => 0, // change for each site
    'timeout' => 0.5,
    'read_timeout' => 0.5,
    'retry_interval' => 10,
    'retries' => 3,
    'backoff' => 'smart',
    'compression' => 'zstd', // `zstd` compresses smaller, `lz4` compresses faster
    'serializer' => 'igbinary',
    'async_flush' => true,
    'split_alloptions' => true,
    'prefetch' => true,
    'strict' => true,
    'debug' => false,
    'save_commands' => false,
]);

define('WP_REDIS_DISABLED', getenv('WP_REDIS_DISABLED') ?: false);

Environment Variables

In some cases you may want to use environment variables to configure the object cache, in PHP you can use the getenv() function to do so.

define('WP_REDIS_CONFIG', [
    'token' => getenv('OBJECTCACHEPRO_TOKEN'),
    'url' => getenv('REDIS_URL'),
    'split_alloptions' => true,
    'async_flush' => true,
    // ...
]);