Moved the hash calculation for a command from ConnectionCluster to the command instance itself.

This commit is contained in:
Daniele Alessandri
2009-12-18 20:43:35 +01:00
parent 3428529be6
commit bcfa64f431
+15 -6
View File
@@ -322,7 +322,7 @@ class Client {
/* ------------------------------------------------------------------------- */
abstract class Command {
private $_arguments;
private $_arguments, $_hash;
public abstract function getCommandId();
@@ -332,6 +332,19 @@ abstract class Command {
return true;
}
public function getHash() {
if (isset($this->_hash)) {
return $this->_hash;
}
else {
if (isset($this->_arguments[0])) {
$this->_hash = crc32($this->_arguments[0]);
return $this->_hash;
}
}
return null;
}
public function closesConnection() {
return false;
}
@@ -778,11 +791,7 @@ class ConnectionCluster implements IConnection, \IteratorAggregate {
}
private function getConnectionFromRing(Command $command) {
return $this->_ring->get(self::computeHash($command));
}
private static function computeHash(Command $command) {
return crc32($command->getArgument(0));
return $this->_ring->get($command->getHash());
}
private function getConnection(Command $command) {