PipeliningCommands.php 1006 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. print_r($replies);
  25. /* OUTPUT:
  26. Array
  27. (
  28. [0] => 1
  29. [1] => 1
  30. [2] => 10
  31. [3] => 40
  32. [4] => 1
  33. [5] => 40
  34. [6] => Array
  35. (
  36. [0] =>
  37. [1] => 40
  38. )
  39. )
  40. */