Forráskód Böngészése

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

Daniele Alessandri 15 éve
szülő
commit
bcfa64f431
1 módosított fájl, 15 hozzáadás és 6 törlés
  1. 15 6
      lib/Predis.php

+ 15 - 6
lib/Predis.php

@@ -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) {