StandardExecutor.php 936 B

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