StandardExecutor.php 957 B

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