Object Cache Pro

Connection

Single Instances #

To connect to a standard Redis instance, use the host and port combination:

define('WP_REDIS_CONFIG', [
'token' => '...',
'host' => '127.0.0.1',
'port' => 6379,
]);

To connect to a unix socket omit the port:

define('WP_REDIS_CONFIG', [
'token' => '...',
'host' => '/var/run/redis/redis-server.sock',
]);

Secure Connections #

To establish a secure connecting using TLS, prefix the host with tls://.

define('WP_REDIS_CONFIG', [
'token' => '...',
'host' => 'tls://10.0.0.3:6379',
'port' => 6379,
]);

TLS connections require PhpRedis 5.3.0 or newer.

Clusters #

To connect to a cluster, provide an array of nodes using the cluster option:

define('WP_REDIS_CONFIG', [
'token' => '...',
'password' => 'secret',
'cluster' => [
'tcp://127.0.0.1:7001',
'tcp://127.0.0.1:7002',
'tcp://127.0.0.1:7003',
'tcp://127.0.0.1:7004',
],
]);

For cluster failover / distribution, see the cluster_failover configuration option.

Replication #

To use a replicated master with read-only replicas, provide the master using the servers configuration option to have the replicas automatically discovered:

define('WP_REDIS_CONFIG', [
'token' => '...',
'servers' => [
'tcp://127.0.0.1:7000?role=master',
],
]);

Alternatively, especially when not using autoscaling, provide a list of replicas:

define('WP_REDIS_CONFIG', [
'token' => '...',
'servers' => [
'tcp://10.0.0.1:6379/?role=master',
'tcp://10.0.0.1:6380/?role=replica',
'tcp://10.0.0.1:6381/?role=replica',
],
]);

By default, read requests are distributed across all replicas as well as the master. To change this behavior see the replication_strategy configuration option.

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('WP_REDIS_TOKEN'),
'prefix' => getenv('WP_REDIS_PREFIX') ?: null,
'maxttl' => getenv('WP_REDIS_MAXTTL') ?: 3600,
]);

Connection Strings #

Heroku, DigitalOcean and other platforms may give you an environment variable with your Redis connection credentials:

REDIS_URL=redis://h:password@127.0.0.1:6379?database=0

You can use the url configuration option to set your host, port and other options:

define('WP_REDIS_CONFIG', [
'token' => '...',
'url' => getenv('REDIS_URL'),
]);