FireAndForget.php 1004 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 SplQueue;
  12. use Predis\Connection\ConnectionInterface;
  13. use Predis\Connection\ReplicationConnectionInterface;
  14. /**
  15. * Command pipeline that writes commands to the servers but discards responses.
  16. *
  17. * @author Daniele Alessandri <suppakilla@gmail.com>
  18. */
  19. class FireAndForget extends Pipeline
  20. {
  21. /**
  22. * {@inheritdoc}
  23. */
  24. protected function executePipeline(ConnectionInterface $connection, SplQueue $commands)
  25. {
  26. if ($connection instanceof ReplicationConnectionInterface) {
  27. $connection->switchTo('master');
  28. }
  29. while (!$commands->isEmpty()) {
  30. $connection->writeCommand($commands->dequeue());
  31. }
  32. $connection->disconnect();
  33. return array();
  34. }
  35. }