redis-sentinel 基于 phpredis 封装的 redis-sentinel 客户端 项目简介
基于 phpredis 扩展的 redis-sentinel 客户端。redis-sentinel 就像他的名字一样,他是一个哨兵,监控 master 状态,如果超过规定时间没有响应,则自动进行主从切换,期间会有一段时间(决定于具体的配置参数)redis集群无法提供服务 。原理类似 mysql 的 MHA。示例:$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);$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);
$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);$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);