lamoda/redis-sentinel

This package is abandoned and no longer maintained. No replacement package was suggested.

Configuration wrapper for redis-sentinel or plain redis

0.3 2022-02-08 08:43 UTC

This package is auto-updated.

Last update: 2023-06-08 11:29:17 UTC


README

Build Status Scrutinizer Code Quality Code Coverage Build Status

Redis configuration wrapper for use with redis sentinel or plain redis server. Used to get connection settings for sentinel or plain old redis if sentinel is not defined (say for dev/test environment).

Usage example

use Lamoda\RedisSentinel\RedisLocator;

$redisLocator = new RedisLocator(
    // plain redis:
    [
        'protocol' => 'tcp',
        'host' => 'redis-host',
        'port' => 6379,
        'dbindex' => 0,
        'connectionName' => uniqid('client-app', true),
    ],
    // redis sentinel:
    [
        'url' => 'redis-sentinel1:26379; redis-sentinel2:26379',
        'redisName' => 'mastername',
    ]
);

// Discover current sentinel master:
$redisConfig = $redisLocator->getRedisConfig();

$redis = new \Redis();
$redis->connect($redisConfig->getHost(), $redisConfig->getPort());
$redis->client('setname', $redisConfig->getConnectionName());
$redis->select($redisConfig->getDbIndex());

Or if you don't have sentinel:

$redisLocator = new RedisLocator(
    // plain redis:
    [
        'protocol' => 'tcp',
        'host' => 'redis-host',
        'port' => 6379,
        'dbindex' => 0,
        'connectionName' => uniqid('client-app', true),
    ],
    // redis sentinel:
    [
        'url' => '',
        'redisName' => 'mastername',
    ]
);

// Return plain redis config:
$redisConfig = $redisLocator->getRedisConfig();

docker-compose for local usage

You can use docker-compose files to ease local sentinel usage & testing.

To start redis-sentinel containers:

docker-compose -f docker/docker-compose.yml up -d

Or using make:

make up
# ...
make down