瀏覽代碼

Remove the ability to execute a command on all the nodes of a cluster.

The reason for this change is that not every cluster implementation can support
this behaviour, think of Redis cluster for example. We moved the implementation
of this method in Predis\Connection\PredisCluster since it can still be useful.
Daniele Alessandri 13 年之前
父節點
當前提交
ec723fd4a9

+ 0 - 21
lib/Predis/Client.php

@@ -240,27 +240,6 @@ class Client
         return $this->connection->executeCommand($command);
     }
 
-    /**
-     * Executes the specified Redis command on all the nodes of a cluster.
-     *
-     * @param CommandInterface $command A Redis command.
-     * @return array
-     */
-    public function executeCommandOnShards(CommandInterface $command)
-    {
-        if (Helpers::isCluster($this->connection)) {
-            $replies = array();
-
-            foreach ($this->connection as $connection) {
-                $replies[] = $connection->executeCommand($command);
-            }
-
-            return $replies;
-        }
-
-        return array($this->connection->executeCommand($command));
-    }
-
     /**
      * Calls the specified initializer method on $this with 0, 1 or 2 arguments.
      *

+ 16 - 0
lib/Predis/Connection/PredisCluster.php

@@ -200,4 +200,20 @@ class PredisCluster implements ClusterConnectionInterface, \IteratorAggregate, \
     {
         return $this->getConnection($command)->executeCommand($command);
     }
+
+    /**
+     * Executes the specified Redis command on all the nodes of a cluster.
+     *
+     * @param CommandInterface $command A Redis command.
+     * @return array
+     */
+    public function executeCommandOnNodes(CommandInterface $command)
+    {
+        $replies = array();
+        foreach ($this->pool as $connection) {
+            $replies[] = $connection->executeCommand($command);
+        }
+
+        return $replies;
+    }
 }

+ 0 - 42
tests/Predis/ClientTest.php

@@ -321,48 +321,6 @@ class ClientTest extends StandardTestCase
         $this->assertTrue($client->executeCommand($ping));
     }
 
-    /**
-     * @group disconnected
-     */
-    public function testExecuteCommandOnEachNode()
-    {
-        $ping = ServerProfile::getDefault()->createCommand('ping', array());
-
-        $connection1 = $this->getMock('Predis\Connection\SingleConnectionInterface');
-        $connection1->expects($this->once())
-                    ->method('executeCommand')
-                    ->with($ping)
-                    ->will($this->returnValue(true));
-
-        $connection2 = $this->getMock('Predis\Connection\SingleConnectionInterface');
-        $connection2->expects($this->once())
-                    ->method('executeCommand')
-                    ->with($ping)
-                    ->will($this->returnValue(false));
-
-        $client = new Client(array($connection1, $connection2));
-
-        $this->assertSame(array(true, false), $client->executeCommandOnShards($ping));
-    }
-
-    /**
-     * @group disconnected
-     */
-    public function testExecuteCommandOnEachNodeButConnectionSingle()
-    {
-        $ping = ServerProfile::getDefault()->createCommand('ping', array());
-
-        $connection = $this->getMock('Predis\Connection\SingleConnectionInterface');
-        $connection->expects($this->once())
-                    ->method('executeCommand')
-                    ->with($ping)
-                    ->will($this->returnValue(true));
-
-        $client = new Client($connection);
-
-        $this->assertSame(array(true), $client->executeCommandOnShards($ping));
-    }
-
     /**
      * @group disconnected
      */

+ 26 - 0
tests/Predis/Connection/PredisClusterTest.php

@@ -321,6 +321,32 @@ class PredisClusterTest extends StandardTestCase
         $cluster->executeCommand($command);
     }
 
+    /**
+     * @group disconnected
+     */
+    public function testExecuteCommandOnEachNode()
+    {
+        $ping = ServerProfile::getDefault()->createCommand('ping', array());
+
+        $connection1 = $this->getMock('Predis\Connection\SingleConnectionInterface');
+        $connection1->expects($this->once())
+                    ->method('executeCommand')
+                    ->with($ping)
+                    ->will($this->returnValue(true));
+
+        $connection2 = $this->getMock('Predis\Connection\SingleConnectionInterface');
+        $connection2->expects($this->once())
+                    ->method('executeCommand')
+                    ->with($ping)
+                    ->will($this->returnValue(false));
+
+        $cluster = new PredisCluster();
+        $cluster->add($connection1);
+        $cluster->add($connection2);
+
+        $this->assertSame(array(true, false), $cluster->executeCommandOnNodes($ping));
+    }
+
     /**
      * @group disconnected
      */