StandardExecutor.php 962 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. namespace Predis\Pipeline;
  3. use Predis\ServerException;
  4. use Predis\Network\IConnection;
  5. class StandardExecutor implements IPipelineExecutor
  6. {
  7. public function execute(IConnection $connection, &$commands)
  8. {
  9. $sizeofPipe = count($commands);
  10. $values = array();
  11. foreach ($commands as $command) {
  12. $connection->writeCommand($command);
  13. }
  14. try {
  15. for ($i = 0; $i < $sizeofPipe; $i++) {
  16. $response = $connection->readResponse($commands[$i]);
  17. $values[] = $response instanceof \Iterator
  18. ? iterator_to_array($response)
  19. : $response;
  20. unset($commands[$i]);
  21. }
  22. }
  23. catch (ServerException $exception) {
  24. // Force disconnection to prevent protocol desynchronization.
  25. $connection->disconnect();
  26. throw $exception;
  27. }
  28. return $values;
  29. }
  30. }