Predis\Connection\Aggregate\PredisCluster::executeCommandOnNodes PHP Method

executeCommandOnNodes() public method

Executes the specified Redis command on all the nodes of a cluster.
public executeCommandOnNodes ( Predis\Command\CommandInterface $command ) : array
$command Predis\Command\CommandInterface A Redis command.
return array
    public function executeCommandOnNodes(CommandInterface $command)
    {
        $responses = array();
        foreach ($this->pool as $connection) {
            $responses[] = $connection->executeCommand($command);
        }
        return $responses;
    }

Usage Example

 /**
  * @group disconnected
  */
 public function testExecuteCommandOnEachNode()
 {
     $ping = Profile\Factory::getDefault()->createCommand('ping', array());
     $connection1 = $this->getMock('Predis\\Connection\\NodeConnectionInterface');
     $connection1->expects($this->once())->method('executeCommand')->with($ping)->will($this->returnValue(true));
     $connection2 = $this->getMock('Predis\\Connection\\NodeConnectionInterface');
     $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));
 }