jenner/redis_sentinel

redis sentinel client for php 5.3+

Installs: 214 300

Dependents: 0

Suggesters: 0

Security: 0

Stars: 50

Watchers: 5

Forks: 18

Type:package

0.3.1 2020-10-27 14:28 UTC

This package is auto-updated.

Last update: 2024-10-27 23:22:27 UTC


README

Latest Stable Version Total Downloads Latest Unstable Version License travis

redis-sentinel client for php based on phpredis extension.

examples

Get Redis master address and create Redis object:

$sentinel = new \Jenner\RedisSentinel\Sentinel();
$sentinel->connect('127.0.0.1', 6379);
$address = $sentinel->getMasterAddrByName('mymaster');

$redis = new Redis();
$redis->connect($address['ip'], $address['port']);
$info = $redis->info();
print_r($info);

Create redis-sentinel pool and create Redis object:

$sentinel_pool = new \Jenner\RedisSentinel\SentinelPool();
$sentinel_pool->addSentinel('127.0.0.1', 26379);
$sentinel_pool->addSentinel('127.0.0.1', 26380);

$address = $sentinel_pool->master('mymaster');
print_r($address);

$redis = $sentinel_pool->getRedis('mymaster');
$info = $redis->info();
print_r($info);

In order to prevent redis/sentinel to wait too long for connections in case of issues with the Redis backend it's advisable to use a timeout (in seconds):

$sentinel_pool->addSentinel('127.0.0.1', 26380, 1.0); # 1 second timeout