Skip to content

Conversation

@turbo124
Copy link
Contributor

Following on from #1144 here is a solution for users who do not wish to load balance reads to slaves. This is via the configuration of the replication strategy in the configuration file.

'sentinel-cache' => array_merge(
    array_map(
        function ($a, $b) {
            return ['host' => $a, 'port' => $b];
        },
        explode(',', env('REDIS_HOST', 'localhost')),
        explode(',', env('REDIS_PORT', 26379))
    ),
    ['options' => [
        'replication' => function () {
                              $strategy = new Predis\Replication\ReplicationStrategy();
                              $strategy->disableLoadBalancing();
                              return new Predis\Connection\Replication\SentinelReplication($strategy);
                          },
        'service' =>  env('REDIS_SENTINEL_SERVICE', 'mymaster'),
        'sentinel_timeout' => 3.0,
        'parameters' => [
            'password' => env('REDIS_PASSWORD', null),
            'database' => env('REDIS_CACHE_DB', 1),
        ],
    ]]
),

This will ensure all read/writes are delivered to the master redis server.

@tillkruss
Copy link
Member

@vladvildanov Any thoughts?

@tillkruss tillkruss self-assigned this Feb 20, 2023
@tillkruss tillkruss added feature client-replication Replication (managed by Predis) labels Feb 20, 2023
@tillkruss tillkruss changed the base branch from main to v2.x February 20, 2023 16:58
@tillkruss tillkruss changed the base branch from v2.x to main February 20, 2023 16:58
@tillkruss
Copy link
Member

@turbo124: The base here is the main (3.x) brach, feel free to rebase to 2.x.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

client-replication Replication (managed by Predis) feature

Development

Successfully merging this pull request may close these issues.

2 participants