Redis Configuration

Last Updated: 03 Feb 2020

Redis cache storage can be configured on a Squiz Matrix system as an alternative to Matrix cache.

The cache storage enhancements using Redis require the phpredis PECL extension installed. For more information, refer to the phpredis documentation (GitHub).

Bookmarks

Configuring the Redis Hosts

Redis host servers can be configured within the system's redis.inc file (~/data/private/conf/redis.inc). The default layout of this file is shown below:

<?php
$redis = array(
    'hosts' => Array (
        'redis1' => Array(
            'socket' => false,
            'host'   => '',
            'port'  => 6379,
        ),
        'redis2' => Array(
            'socket' => false,
            'host'   => '',
            'port'  => 6380,
        ),
    ),

    // List of Matrix services utilising the above servers.
    // Indexed by key => weight.
    'services'  => Array(
        'cache_manager'    => Array('redis1' => 1, 'redis2' => 1),
        'session_handling' => Array('redis1' => 1, 'redis2' => 1),
        'locking'          => Array('redis1' => 1, 'redis2' => 1),
        'deja_vu'          => Array('redis1' => 1, 'redis2' => 1),
    ), ); return $redis;

Multiple hosts can be defined within this array, as displayed in the default layout of the file. The parameters available for configuration in each child of the hosts key are as follows:

  • socket: the path to a Unix domain socket to connect to. Please note that entering socket information within this parameter will override any host and port values that have been set. By default, this option is set to False.
  • host: the hostname of the Redis server where the Redis server is listening for connections.
  • port: the port of the Redis server. By default, this is set to 6379 (default port) for the redis1 host, and 6380 for the redis2 host.
  • database: which database in Redis to use (default is 0)
  • persistent: whether to keep the connection open for the duration of the PHP request (default is false)
  • persistent_id: the identifier for a persistent connection (default is '')
  • retry_interval: time between reconnection attempts in milliseconds (default is 2)
  • prefix: a prefix for all keys (default is '')
  • connection_timeout: the maximum amount of time in seconds to wait while connecting to redis (default is 2)
  • read_timeout: a maximum amount of time in seconds to wait for data from Redis (default is 0, which is unlimited)

For more information on these parameters, refer to the Redis documentation.

Setting Up the Redis Services

Squiz Matrix offers Redis services that can be configured within the system's redis.inc file (~/data/private/conf/redis.inc) once the Redis host servers have been configured. The default layout of the services section of the redis.inc file is shown below:

'cache_manager'     => Array('redis1' => 1, 'redis2' => 1),
'session_handling'  => Array('redis1' => 1, 'redis2' => 1),
'locking'           => Array('redis1' => 1, 'redis2' => 1),
'deja_vu'           => Array('redis1' => 1, 'redis2' => 1),

By default, the cache_manager service will be utilising the redis1 and redis2 default host set up.

To configure hosts for these redis services, add the host server ID to the service array, as follows:

'cache_manager'     => Array('redis1' => 1)

In this example, the redis1 host server has been set to 1 (true). You can configure multiple hosts on these services, as in the default host set up. This is useful to create a fallback if the initial host cannot be reached or fails. This is achieved like so:

'cache_manager'     => Array('redis1' => 1, 'redis2' => 1

Continue reading below for more information on the services available for Redis.

Cache Manager

The Redis cache_manager service allows you to store Matrix cache entries within Redis rather than the default SQ_CACHE directory (specified in main.inc).

The cache storage system is fully optional for Redis and is configured in the redis.inc file. The default set up of this service is as follows:

'cache_manager'     => Array('redis1' => 1, 'redis2' => 1)

Once you have configured the redis.inc file, you can enable Redis cache storage on the Details screen of the Cache Manager.

5-0-0_redis-cache-storage.png
The Redis Cache Storage option

In the Cache Storage Type field, select Redis Cache Storage and click Commit. Redis cache storage will now be enabled on your system, using the Redis server settings specified in the redis.inc file.


Previous Chapter Next Chapter