StandardExecutor.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. /*
  3. * This file is part of the Predis package.
  4. *
  5. * (c) Daniele Alessandri <suppakilla@gmail.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Predis\Pipeline;
  11. use Predis\ServerException;
  12. use Predis\Network\IConnection;
  13. class StandardExecutor implements IPipelineExecutor
  14. {
  15. public function execute(IConnection $connection, &$commands)
  16. {
  17. $sizeofPipe = count($commands);
  18. $values = array();
  19. foreach ($commands as $command) {
  20. $connection->writeCommand($command);
  21. }
  22. try {
  23. for ($i = 0; $i < $sizeofPipe; $i++) {
  24. $response = $connection->readResponse($commands[$i]);
  25. $values[] = $response instanceof \Iterator
  26. ? iterator_to_array($response)
  27. : $response;
  28. unset($commands[$i]);
  29. }
  30. }
  31. catch (ServerException $exception) {
  32. // Force disconnection to prevent protocol desynchronization.
  33. $connection->disconnect();
  34. throw $exception;
  35. }
  36. return $values;
  37. }
  38. }