Refactored Client::executeCommand and introduced the new method Client::executeCommandOnShards which is useful to execute commands on all the connections registered in a ConnectionCluster instance.

This commit is contained in:
Daniele Alessandri
2009-12-14 18:02:54 +01:00
parent 8d4958a516
commit 344ec44059
+21 -4
View File
@@ -104,12 +104,29 @@ class Client {
return $command;
}
public function executeCommand(Command $command) {
$this->_connection->writeCommand($command);
private function executeCommandInternal(Connection $connection, Command $command) {
$connection->writeCommand($command);
if ($command->closesConnection()) {
return $this->_connection->disconnect();
return $connection->disconnect();
}
return $this->_connection->readResponse($command);
return $connection->readResponse($command);
}
public function executeCommand(Command $command) {
return self::executeCommandInternal($this->_connection, $command);
}
public function executeCommandOnShards(Command $command) {
$replies = array();
if (is_a($this->_connection, '\Predis\ConnectionCluster')) {
foreach($this->_connection as $connection) {
$replies[] = self::executeCommandInternal($connection, $command);
}
}
else {
$replies[] = self::executeCommandInternal($this->_connection, $command);
}
return $replies;
}
public function rawCommand($rawCommandData, $closesConnection = false) {