getCluster() public method

If a Credis_Cluster object exists, return it. Otherwise create one and return it.
Deprecation:
public getCluster ( string $name, integer $db, integer $replicas = 128, boolean $selectRandomSlave = true, boolean $writeOnly = false ) : Credis_Cluster
$name string
$db integer
$replicas integer
$selectRandomSlave boolean
$writeOnly boolean
return Credis_Cluster
Exemplo n.º 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']);
 }
Exemplo n.º 2
0
 public function testGetClusterOnDbNumber2()
 {
     $cluster = $this->sentinel->getCluster($this->sentinelConfig->clustername, 2);
     $this->assertInstanceOf('Credis_Cluster', $cluster);
     $this->assertCount(2, $cluster->clients());
     $clients = $cluster->clients();
     $this->assertEquals(2, $clients[0]->getSelectedDb());
     $this->assertEquals(2, $clients[1]->getSelectedDb());
 }
Exemplo n.º 3
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);
 }