PipeliningCommands.php 975 B

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 'SharedConfigurations.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. $replies = $client->pipeline(function ($pipe) {
  16. $pipe->ping();
  17. $pipe->flushdb();
  18. $pipe->incrby('counter', 10);
  19. $pipe->incrby('counter', 30);
  20. $pipe->exists('counter');
  21. $pipe->get('counter');
  22. $pipe->mget('does_not_exist', 'counter');
  23. });
  24. var_export($replies);
  25. /* OUTPUT:
  26. array (
  27. 0 => true,
  28. 1 => true,
  29. 2 => 10,
  30. 3 => 40,
  31. 4 => true,
  32. 5 => '40',
  33. 6 =>
  34. array (
  35. 0 => NULL,
  36. 1 => '40',
  37. ),
  38. )
  39. */