فهرست منبع

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.

Daniele Alessandri 15 سال پیش
والد
کامیت
344ec44059
1فایلهای تغییر یافته به همراه21 افزوده شده و 4 حذف شده
  1. 21 4
      lib/Predis.php

+ 21 - 4
lib/Predis.php

@@ -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 $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 $this->_connection->readResponse($command);
+        return $replies;
     }
 
     public function rawCommand($rawCommandData, $closesConnection = false) {