lamoda / redis-sentinel
Configuration wrapper for redis-sentinel or plain redis
Installs: 934
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 16
Forks: 1
Open Issues: 0
pkg:composer/lamoda/redis-sentinel
Requires
- php: >=7.1 | >=8.0
- jamescauwelier/psredis: ^1.1
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.14
- phpunit/phpunit: ^7.0 | ^9.0
This package is auto-updated.
Last update: 2023-06-08 11:29:17 UTC
README
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