mirror of
https://github.com/predis/predis.git
synced 2026-09-11 19:07:30 +00:00
Moved the hash calculation for a command from ConnectionCluster to the command instance itself.
This commit is contained in:
+15
-6
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user