pipelining_commands.php 1006B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. require __DIR__.'/shared.php';
  11. // When you have a whole set of consecutive commands to send to a redis server,
  12. // you can use a pipeline to dramatically improve performances. Pipelines can
  13. // greatly reduce the effects of network round-trips.
  14. $client = new Predis\Client($single_server);
  15. $responses = $client->pipeline(function ($pipe) {
  16. $pipe->flushdb();
  17. $pipe->incrby('counter', 10);
  18. $pipe->incrby('counter', 30);
  19. $pipe->exists('counter');
  20. $pipe->get('counter');
  21. $pipe->mget('does_not_exist', 'counter');
  22. });
  23. var_export($responses);
  24. /* OUTPUT:
  25. array (
  26. 0 => Predis\Response\Status::__set_state(array(
  27. 'payload' => 'OK',
  28. )),
  29. 1 => 10,
  30. 2 => 40,
  31. 3 => true,
  32. 4 => '40',
  33. 5 => array (
  34. 0 => NULL,
  35. 1 => '40',
  36. ),
  37. )
  38. */