Implements the Sentinel API as mentioned on http://redis.io/topics/sentinel. Sentinel is aware of master and slave nodes in a cluster and returns instances of Credis_Client accordingly. The complexity of read/write splitting can also be abstract by calling the createCluster() method which returns a Credis_Cluster object that contains both the master server and a random slave. Credis_Cluster takes care of the read/write splitting
Автор: Thijs Feryn (thijs@feryn.eu)
Пример #1
0
 private function init()
 {
     /**
      * 如果redis使用集群并且加入sentinel做灾备切换,这里可以实现,使用下面的类, 可以实现自动切换,但效率会受到比较大的影响
      */
     $sentinel = new Credis_Sentinel(new Credis_Client($this->_cfg['sentinel_host'], $this->_cfg['sentinel_port']));
     $this->_cluster = $sentinel->getCluster($this->_cfg['master_name'], $this->_cfg['password']);
 }
Пример #2
0
 private function init()
 {
     if (0) {
         /**
          * 如果redis使用集群并且加入sentinel做灾备切换,这里可以实现,使用下面的类, 可以实现自动切换,但效率会受到比较大的影响
          */
         $sentinel = new Credis_Sentinel(new Credis_Client($this->_cfg['sentinel_host'], $this->_cfg['sentinel_port']));
         $this->_cluster = $sentinel->getCluster($this->_cfg['master_name'], $this->_cfg['password']);
     } else {
         $this->_cluster = new Redis();
     }
     $this->_cluster->pconnect('127.0.0.1', 6380);
 }
Пример #3
0
 public function testNonExistingMethod()
 {
     $this->setExpectedException('CredisException', 'Unknown sentinel subcommand \'bla\'');
     $this->sentinel->bla();
 }