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.
This commit is contained in:
Daniele Alessandri
2012-02-07 15:40:19 +01:00
parent b67af29eb6
commit ec723fd4a9
4 changed files with 42 additions and 63 deletions
-21
View File
@@ -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
View File
@@ -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;
}
}
-42
View File
@@ -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
*/
@@ -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
*/