FireAndForgetExecutor.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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\Network\IConnection;
  12. use Predis\Network\IConnectionReplication;
  13. /**
  14. * Implements a pipeline executor strategy that writes a list of commands to
  15. * the connection object but does not read back their replies.
  16. *
  17. * @author Daniele Alessandri <suppakilla@gmail.com>
  18. */
  19. class FireAndForgetExecutor implements IPipelineExecutor
  20. {
  21. /**
  22. * Allows the pipeline executor to perform operations on the
  23. * connection before starting to execute the commands stored
  24. * in the pipeline.
  25. *
  26. * @param IConnection Connection instance.
  27. */
  28. protected function checkConnection(IConnection $connection)
  29. {
  30. if ($connection instanceof IConnectionReplication) {
  31. $connection->switchTo('master');
  32. }
  33. }
  34. /**
  35. * {@inheritdoc}
  36. */
  37. public function execute(IConnection $connection, &$commands)
  38. {
  39. $this->checkConnection($connection);
  40. foreach ($commands as $command) {
  41. $connection->writeCommand($command);
  42. }
  43. $connection->disconnect();
  44. return array();
  45. }
  46. }