Credis_Sentinel::createSlaveClients PHP Method

createSlaveClients() public method

Discover the slave nodes automatically and return an array of Credis_Client objects
public createSlaveClients ( string $name ) : Credis_Client[]
$name string
return Credis_Client[]
    public function createSlaveClients($name)
    {
        $slaves = $this->slaves($name);
        $workingSlaves = array();
        foreach ($slaves as $slave) {
            if (!isset($slave[9])) {
                throw new CredisException('Can\' retrieve slave status');
            }
            if (!strstr($slave[9], 's_down') && !strstr($slave[9], 'disconnected')) {
                $workingSlaves[] = new Credis_Client($slave[3], $slave[5], $this->_timeout, $this->_persistent, $this->_db, $this->_password);
            }
        }
        return $workingSlaves;
    }

Usage Example

コード例 #1
0
 public function testNonExistingClusterNameWhenCreatingSlaves()
 {
     $this->setExpectedException('CredisException', 'No such master with that name');
     $this->sentinel->createSlaveClients('non-existing-cluster');
 }