CommandPipeline.php 730 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. require_once 'SharedConfigurations.php';
  3. // when you have a whole set of consecutive commands to send to
  4. // a redis server, you can use a pipeline to improve performances.
  5. $redis = new Predis\Client(REDIS_HOST, REDIS_PORT);
  6. $redis->select(REDIS_DB);
  7. $replies = $redis->pipeline(function($pipe) {
  8. $pipe->ping();
  9. $pipe->flushdb();
  10. $pipe->incrby('counter', 10);
  11. $pipe->incrby('counter', 30);
  12. $pipe->exists('counter');
  13. $pipe->get('counter');
  14. $pipe->mget('does_not_exist', 'counter');
  15. });
  16. print_r($replies);
  17. /* OUTPUT:
  18. Array
  19. (
  20. [0] => 1
  21. [1] => 1
  22. [2] => 10
  23. [3] => 40
  24. [4] => 1
  25. [5] => 40
  26. [6] => Array
  27. (
  28. [0] =>
  29. [1] => 40
  30. )
  31. )
  32. */
  33. ?>