123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- <?php
- namespace Predis\Pipeline;
- use Predis\ServerException;
- use Predis\Network\IConnection;
- use Predis\Network\IConnectionReplication;
- class StandardExecutor implements IPipelineExecutor
- {
-
- protected function checkConnection(IConnection $connection)
- {
- if ($connection instanceof IConnectionReplication) {
- $connection->switchTo('master');
- }
- }
-
- public function execute(IConnection $connection, &$commands)
- {
- $sizeofPipe = count($commands);
- $values = array();
- $this->checkConnection($connection);
- foreach ($commands as $command) {
- $connection->writeCommand($command);
- }
- try {
- for ($i = 0; $i < $sizeofPipe; $i++) {
- $response = $connection->readResponse($commands[$i]);
- $values[] = $response instanceof \Iterator
- ? iterator_to_array($response)
- : $response;
- unset($commands[$i]);
- }
- }
- catch (ServerException $exception) {
-
- $connection->disconnect();
- throw $exception;
- }
- return $values;
- }
- }
|