Configuration Options
- Overview
- Token
- Client
- Host
- Port
- Database
- Username
- Password
- Prefix
- MaxTTL
- Timeout
- Read Timeout
- Retry Interval
- Retries
- Backoff Algorithm
- Persistent
- Shared
- Asynchronous Flushing
- Group Flushing
- Cluster
- Cluster Failover
- Sentinels
- Service
- Servers
- Replication Strategy
- Tracer
- Serializer
- Compression
- Global Groups
- Non-persistent Groups
- Non-prefetchable Groups
- Analytics
- Relay
- Prefetching
- Splitting “alloptions”
- Flushing Networks
- TLS Options
- Strict
- Updates
- Cache
- Connector
- Logger
- Log Levels
- Debug
- Save Commands
Overview
The configuration options and their default values:
define('WP_REDIS_CONFIG', [
// (string) Your license token
'token' => null,
// (string) The name of the client
'client' => null,
// (string) The logger class name
'logger' => null,
// (array) Log levels
'log_levels' => ['emergency', 'alert', 'critical', 'error'],
// (string) The hostname of the instance
'host' => null,
// (integer) The port of the instance
'port' => null,
// (integer) The Redis database
'database' => 0,
// (string) The connection's username (Redis 6+).
'username' => null,
// (string) The connection's password
'password' => null,
// (string) The prefix for all keys
'prefix' => null,
// (integer) The maximum time-to-live in seconds
'maxttl' => null,
// (float) Connection timeout in seconds
'timeout' => 0.0,
// (float) Read timeout in seconds
'read_timeout' => 0.0,
// (integer) Retry interval in milliseconds
'retry_interval' => 0,
// (int) The amount of retries
'retries' => 3,
// (string) The backoff algorithm.
'backoff' => 'smart',
// (bool) Whether the connection is persistent
'persistent' => false,
// (bool) Whether the Redis server is shared between multiple apps
'shared' => false,
// (bool) Whether flushing is asynchronous (Redis 4+)
'async_flush' => false,
// (string) Whether flushing is asynchronous
// `keys`, `scan`, `incremental`
'group_flush' => 'keys',
// (string) Multisite flushing strategy
// `all`, `site`, `global`
'network_flush' => 'all',
// (array|string) The cluster configuration name as string, or an array of cluster nodes
'cluster' => null,
// (string) Replica failover / distribution strategy
// `none`, `error`, `distribute`, `distribute_replicas`
'cluster_failover' => 'none',
// (array) The array of Redis Sentinels
'sentinels' => null,
// (string) The Redis Sentinel service name.
'service' => null,
// (array) An array of replicated Redis servers
'servers' => null,
// (string) Replication failover strategy
// `distribute`, `distribute_replicas`, `concentrate`
'replication_strategy' => 'distribute',
// (string) The used tracer
// `none`, `newrelic`
'tracer' => 'none',
// (string) The data serializer
// `php`, `igbinary`
'serializer' => 'php',
// (string) The data compression format
// `none`, `lzf`, `lz4` (fastest), `zstd` (smallest)
'compression' => 'none',
// (array) The list of global cache groups that are not blog-specific in a network environment
'global_groups' => null,
// (array) The non-persistent groups that will only be cached for the duration of a request
'non_persistent_groups' => null,
// (array) The non-prefetchable groups that will not be prefetched
'non_prefetchable_groups' => null,
// (array) The analytics configuration
'analytics' => [
// (bool) Whether to collect and display analytics
'enabled' => true,
// (bool) Whether to restore analytics data after cache flushes
'persist' => true,
// (int) The number of seconds to keep analytics before purging them
'retention' => 60 * 60 * 2,
// (bool) Whether to print a HTML comment with non-sensitive metrics
'footnote' => true,
],
// (array) The Relay configuration options
'relay' => [
// (bool) Whether to register Relay event listeners
'listeners' => false,
// (bool) Whether to enable client-side invalidation
'invalidations' => true,
// (array) Keys matching these patterns will not be cached in Relay's in-memory cache
'ignored' => ['*:analytics:*'],
// When set, only keys matching these patterns will be cached in Relay's in-memory cache, unless they match `relay.ignored`
'allowed' => null,
],
// (bool) Whether to batch prefetch keys for requests
'prefetch' => false,
// (bool) Whether the `alloptions` key should be stored as a hash
'split_alloptions' => false,
// (array) The TLS context options, such as `verify_peer` and `ciphers`.
'tls_options' => null,
// (bool) Whether to enable strict mode
'strict' => true,
// (bool) Whether to enable plugin updates
'updates' => false,
// (string) The object cache class name
'cache' => null,
// (string) The connector class name
'connector' => null,
// (bool) Whether debug mode is enabled
'debug' => false,
// (bool) Whether all executed commands should be logged
'save_commands' => false,
]);
Token
The token
option should be set to the license token you received when after purchasing. It’s a 60 characters long string and will enable automatic plugin updates and unlock features.
define('WP_REDIS_CONFIG', [
'token' => '02269ec4add8cac59...',
]);
Client
The client
option determines the Redis client used for connections. It defaults to phpredis
. If you have Relay installed, please read these notes carefully.
define('WP_REDIS_CONFIG', [
'client' => 'phpredis',
]);
Host
The host
option defines the IP address, hostname unit socket and scheme used to connect to Redis.
define('WP_REDIS_CONFIG', [
'host' => '127.0.0.1'
'host' => 'tcp://127.0.0.1'
'host' => 'tls://xxxxxx.cache.amazonaws.com',
'host' => '/var/run/redis/redis-server.sock',
]);
Port
The port
option is mandatory when connecting to a single instance via TCP or TLS.
define('WP_REDIS_CONFIG', [
'port' => 6379,
]);
Database
The database
option determines Redis database used to store all cache data. The default is 0
.
define('WP_REDIS_CONFIG', [
'database' => 2,
]);
Username
When use Redis 6.0 ACLs, use the username
option to specify the connection’s username.
define('WP_REDIS_CONFIG', [
'username' => 'wordpress',
]);
Password
The password
configuration option will be used to authenticate.
define('WP_REDIS_CONFIG', [
'password' => 'super-s3cret',
]);
Prefix
Similar to WP’s $table_prefix
variable, which prefixes all database table names, the prefix
option will place the given string in front of all cache keys.
define('WP_REDIS_CONFIG', [
'prefix' => 'mysitename',
]);
MaxTTL
The maxttl
option will enforce a “maximum time-to-live” for all new cache keys in seconds. It’s value must be an integer
.
This option will only affect keys created in the future. You might want to flush your cache once to purge keys without an expiration.
define('WP_REDIS_CONFIG', [
'maxttl' => 3600 * 24, // 24 hours
]);
Timeout
The connection timeout to Redis, expressed in seconds.
define('WP_REDIS_CONFIG', [
'timeout' => 1.5, // 1.5 seconds
]);
Read Timeout
The connection’s read timeout, expressed in seconds.
define('WP_REDIS_CONFIG', [
'read_timeout' => 1.5, // 1.5 seconds
]);
Retry Interval
The connection’s retry interval, expressed in milliseconds.
define('WP_REDIS_CONFIG', [
'retry_interval' => 300, // 0.3 seconds
]);
Retries
When using PhpRedis 5.3.5+ or Relay, you may set the maximum retries
upon connection issues.
define('WP_REDIS_CONFIG', [
'retries' => 3,
]);
Backoff Algorithm
When using the retries
configuration the smart
backoff configuration is used which is composed of:
- Decorrelated jitter algorithm
- Base for backoff computation is
retry_interval
- Backoff time capped at
read_timeout
define('WP_REDIS_CONFIG', [
'backoff' => 'smart',
]);
Persistent
Defines if a persistent connection should be used.
define('WP_REDIS_CONFIG', [
'persistent' => true,
]);
Shared
Whether the Redis server/cluster is shared or dedicated. This affects how memory and key counts are displayed.
define('WP_REDIS_CONFIG', [
'shared' => true,
]);
Asynchronous Flushing
Asynchronous flushing was introduced in Redis 4.0 and can be enabled using the async_flush
option. It allows deleting large amounts of keys in the background without blocking the server.
define('WP_REDIS_CONFIG', [
'async_flush' => true, // boolean
]);
Group Flushing
By default cache groups as flushes using a Lua script and the SCAN
command. In some scenarios using Lua and the KEYS
command may be faster. Installations with 10M and more the incremental
group flush might perform better by avoiding Lua script timeouts.
define('WP_REDIS_CONFIG', [
'group_flush' => 'keys', // `keys`, `scan`, `incremental`
]);
Cluster
To connect to a cluster, provide an array of primary nodes using the cluster configuration option, instead of using host
:
define('WP_REDIS_CONFIG', [
'cluster' => [
'tcp://172.17.0.1:6379',
'tcp://172.17.0.1:6379',
'tcp://172.17.0.1:6379',
],
]);
Cluster Failover
When using a Redis cluster commands will only ever be send to primary nodes, but can be configured differently for read-only commands if requested.
define('WP_REDIS_CONFIG', [
// Only send commands to primary nodes
'cluster_failover' => 'none',
// If a primary can't be reached, and it has replicas, failover for read commands
'cluster_failover' => 'error',
// Always distribute readonly commands between primaries and replicas, at random
'cluster_failover' => 'distribute',
// Always distribute readonly commands to the replicas, at random
'cluster_failover' => 'distribute_replicas',
]);
Sentinels
To connect to Redis Sentinel, provide the Sentinel nodes using the sentinels
configuration option, instead of using host
:
define('WP_REDIS_CONFIG', [
'sentinels' => [
'tcp://172.17.0.1:6379',
'tcp://172.17.0.1:6379',
'tcp://172.17.0.1:6379',
],
]);
Service
When using Redis Sentinel, use the service
configuration option to provide the Sentinel service name:
define('WP_REDIS_CONFIG', [
'service' => 'my-cache',
]);
Servers
To use a replicated primary with read-only replicas, provide the primary using the servers
configuration option to have the replicas automatically discovered:
define('WP_REDIS_CONFIG', [
'token' => '...',
'servers' => [
'tcp://127.0.0.1:7000?role=primary',
],
]);
You may also specify the read replicas.
Replication Strategy
By default read requests are distributed across all replicas as well as the primary. To change this behavior use the replication_strategy
configuration option.
define('WP_REDIS_CONFIG', [
// Distribute readonly commands between primary and replicas, at random
'replication_strategy' => 'distribute',
// Distribute readonly commands to the replicas, at random
'replication_strategy' => 'distribute_replicas',
// Send readonly commands to a single, random replica
'replication_strategy' => 'concentrate',
]);
Tracer
The tracer
configuration option determines which tracer the underlying client will use.
Object Cache Pro will determine the best tracer to use based on the system it runs on. The default is none
.
define('WP_REDIS_CONFIG', [
'tracer' => 'newrelic',
]);
Aside from New Relic, Datadog, Blackfire and Scout APM any Open Telemetry tracer (like Uptrace) is supported.
Serializer
All data store in Redis is serialized using PHP’s serialize()
and unserialize()
functions.
Alternatively you can use igbinary
, which is a drop in replacement that stores php data structures in a compact binary form. The average reduction in size is around 50%.
Supported values are php
and igbinary
.
To avoid corrupt data and crashing your site, learn more about enabling and switching data serializer.
define('WP_REDIS_CONFIG', [
'serializer' => 'igbinary', // store data in binary format
]);
Compression
The compression
option determines the data compression algorithm used for all data stored in Redis.
Supported algorithms are lzf
, lz4
and zstd
. All algorithms require PhpRedis to be compiled with support for them. The default is none
(no data compression).
To avoid corrupt data and crashing your site, learn more about enabling and switching data compression.
define('WP_REDIS_CONFIG', [
'compression' => 'zstd', // Zstandard (level 3)
]);
The zstd
algorithm compresses data the smallest, lz4
compresses data the fastest and lzf
should only be used the others aren’t available.
Global Groups
The list of global cache groups that are not blog-specific in a network environment. These will be added in addition to what WordPress Core defines as global groups.
define('WP_REDIS_CONFIG', [
'global_groups' => ['redirects', '...'],
]);
Non-persistent Groups
The non-persistent groups that will only be cached for the duration of a request. These will be added in addition to what WordPress Core defines as non-persistent groups.
define('WP_REDIS_CONFIG', [
'non_persistent_groups' => [
'wc_session_id',
'*-queries', // wildcard are supported
],
]);
Non-prefetchable Groups
The non-prefetchable groups that will not be prefetched.
define('WP_REDIS_CONFIG', [
'non_prefetchable_groups' => [
'wc_session_id',
'*-queries', // wildcard are supported
],
]);
Analytics
The analytics configuration option allow you to configure:
- Whether to collect and display analytics
- Whether to restore analytics data after cache flushes
- The number of seconds to keep analytics before purging them
- The sample rate for analytics in the range of
0
to100
(if set to20
only 20% of randomly picked requests are measured) - Whether to print a HTML comment with non-sensitive metrics
define('WP_REDIS_CONFIG', [
'analytics' => [
'enabled' => true,
'persist' => true,
'retention' => 3600, // 1 hour
'sample_rate' => 100,
'footnote' => true,
],
]);
Relay
The Relay configuration option allow you to configure:
- Whether to use Relay’s in-memory cache
- Whether to register Relay event listeners
- Whether to enable client-side invalidation
- Which key patterns are and aren’t stored in Relay’s in-memory cache
These are the defaults:
define('WP_REDIS_CONFIG', [
'relay' => [
'cache' => true,
'listeners' => false,
'invalidations' => true,
'allowed' => null,
'ignored' => [
'*:analytics:*',
],
],
]);
Prefetching
When prefetching is enabled the requested cache keys are stored on a per-request basis and batch loaded per group early on for consecutive requests.
The list of prefetchable keys is updated each request to keep it fresh.
define('WP_REDIS_CONFIG', [
'prefetch' => true,
// 'non_prefetchable_groups' => ['wpseo', '...'],
]);
Splitting “alloptions”
Whether the alloptions
key should be split into individual keys and stored in a hash. This will help avoid race conditions in some scenarios.
When using Relay the alloptions
key is stored in individual keys to avoid unnecessary invalidations.
The alloptions
hash does not obey the maxttl
option.
define('WP_REDIS_CONFIG', [
'split_alloptions' => true, // use hash for `alloptions` key
]);
Flushing Networks
Since individual sites in a multisite network share data such as users, logins and transients, by default the entire Redis database is flushed when wp_cache_flush()
is called using the all
option.
When using Redis 4.0.0 (or newer), you may only flush the data of an individual site, by setting the network_flush
configuration option to site
. Or if you also want to flush all global groups, but not data from other sites, set network_flush
to global
.
define('WP_REDIS_CONFIG', [
'network_flush' => 'global', // only flush individual sites
]);
On Redis Cluster the configuration option could be slow, especially the global
option.
TLS Options
When using tls://
transports, you may set the context options, such as verify_peer
and ciphers
using the tls_options
configuration option:
define('WP_REDIS_CONFIG', [
'tls_options' => [
'verify_peer' => false,
],
]);
A full list of SSL/TLS context options is available on php.net.
Strict
Whether to enable strict mode perform cache integrity protection flushes (enabled by default, if no prefix
is set).
define('WP_REDIS_CONFIG', [
'strict' => true,
]);
Updates
Whether to enable plugin updates and show updates and update notices within WordPress (enabled by default).
define('WP_REDIS_CONFIG', [
'updates' => false,
]);
Cache
The cache
configuration option allows a custom object cache implementation to be set. It must implement the RedisCachePro\ObjectCaches\ObjectCacheInterface
interface.
Using a fully qualified class name requires you to load the class before using it:
require_once __DIR__ . '/wp-content/plugins/object-cache-pro/bootstrap.php';
require_once __DIR__ . '/path/to/MyObjectCache.php'
define('WP_REDIS_CONFIG', [
'cache' => MyObjectCache::class,
]);
We strongly recommend extending the existing PhpRedisObjectCache
class:
<?php
# MyObjectCache.php
class MyObjectCache extends RedisCachePro\ObjectCaches\PhpRedisObjectCache
{
//
}
Connector
The connector
configuration option allows a custom connector to be set. It must implement the RedisCachePro\Connectors\Connector
interface.
Using a fully qualified class name requires you to load the class before using it:
require_once __DIR__ . '/wp-content/plugins/object-cache-pro/bootstrap.php';
require_once __DIR__ . '/path/to/MyConnector.php';
define('WP_REDIS_CONFIG', [
'connector' => MyConnector::class,
]);
To use the built-in Twemproxy support, set the value to twemproxy
.
Logger
The logger
configuration option allows a custom log class to be set. Read more about it in the logging documentation.
Log Levels
The log_levels
option defaults to ['emergency', 'alert', 'critical', 'error']
and all errors with these levels will be logged in silent mode by the ErrorLogLogger
.
The available logging levels are:
define('WP_REDIS_CONFIG', [
'log_levels' => [
'emergency', // System is unusable
'alert', // Action must be taken immediately
'critical', // Critical conditions
'error', // Runtime errors that do not require immediate action but should typically be logged and monitored
'warning', // Exceptional occurrences that are not errors
'notice', // Normal but significant events
'info', // Interesting events
'debug', // Detailed debug information
],
]);
Debug
The debug
configuration option is described in detail under Debugging.
Save Commands
The save_commands
configuration option allow for all cache commands to be logged (and displayed in Query Monitor) without enabling the debug
or WP_DEBUG
options.