public function createCluster($name, $db = 0, $replicas = 128, $selectRandomSlave = true, $writeOnly = false)
{
$clients = array();
$workingClients = array();
$master = $this->master($name);
if (strstr($master[9], 's_down') || strstr($master[9], 'disconnected')) {
throw new CredisException('The master is down');
}
$slaves = $this->slaves($name);
foreach ($slaves as $slave) {
if (!strstr($slave[9], 's_down') && !strstr($slave[9], 'disconnected')) {
$workingClients[] = array('host' => $slave[3], 'port' => $slave[5], 'master' => false, 'db' => $db, 'password' => $this->_password);
}
}
if (count($workingClients) > 0) {
if ($selectRandomSlave) {
if (!$writeOnly) {
$workingClients[] = array('host' => $master[3], 'port' => $master[5], 'master' => false, 'db' => $db, 'password' => $this->_password);
}
$clients[] = $workingClients[rand(0, count($workingClients) - 1)];
} else {
$clients = $workingClients;
}
}
$clients[] = array('host' => $master[3], 'port' => $master[5], 'db' => $db, 'master' => true, 'write_only' => $writeOnly, 'password' => $this->_password);
return new Credis_Cluster($clients, $replicas, $this->_standAlone);
}