0

We have an existing load balanced / HA deployment of Craft 3.4, to which I want to add support for the redis replica we have available, but I can't work out how to correctly configure this in config/app.php.

For a single redis server I have this config and it works fine:

...
    'components' => [
        'redis' => [
            'class' => yii\redis\Connection::class,
            'hostname' => getenv('REDIS_HOST'),
            'password' => getenv('REDIS_PASS'),
            'port' => 6379,
        ],
        'cache' => [
            'class' => yii\redis\Cache::class,
            'defaultDuration' => 86400,
        ],
        'session' => [
            'class' => yii\redis\Session::class,
            'as session' => craft\behaviors\SessionBehavior::class,
        ],
...

Here's what I'm trying for replicas based on the yii-redis-cache docs, but which doesn't work:

    'components' => [
        'redis' => [
            'class' => yii\redis\Connection::class,
            'hostname' => getenv('REDIS_HOST'),
            'password' => getenv('REDIS_PASS'),
            'port' => 6379,
        ],
        'cache' => [
            'class' => yii\redis\Cache::class,
            'enableReplicas' => true,
            'defaultDuration' => 86400,
            'replicas' => [
                 'redis',
                 ['hostname' => getenv('REDIS_HOST')],
                 ['hostname' => getenv('REDIS_SLAVE_HOST')],
            ],
        ],
        'session' => [
            'class' => yii\redis\Session::class,
            'as session' => craft\behaviors\SessionBehavior::class,
        ],

How do I configure Craft to use both the redis servers available?

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.