Credis_Sentinel::getCluster PHP Method

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
    public function getCluster($name, $db = 0, $replicas = 128, $selectRandomSlave = true, $writeOnly = false)
    {
        if (!isset($this->_cluster[$name])) {
            $this->_cluster[$name] = $this->createCluster($name, $db, $replicas, $selectRandomSlave, $writeOnly);
        }
        return $this->_cluster[$name];
    }

Usage Example

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']);
 }
All Usage Examples Of Credis_Sentinel::getCluster