MultipleSetAndGet.php 569 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. require_once 'SharedConfigurations.php';
  3. // redis can set keys and their relative values in one go
  4. // using MSET, then the same values can be retrieved with
  5. // a single command using MGET.
  6. $mkv = array(
  7. 'usr:0001' => 'First user',
  8. 'usr:0002' => 'Second user',
  9. 'usr:0003' => 'Third user'
  10. );
  11. $redis = new Predis\Client(REDIS_HOST, REDIS_PORT);
  12. $redis->select(REDIS_DB);
  13. $redis->mset($mkv);
  14. $retval = $redis->mget(array_keys($mkv));
  15. print_r($retval);
  16. /* OUTPUT:
  17. Array
  18. (
  19. [0] => First user
  20. [1] => Second user
  21. [2] => Third user
  22. )
  23. */
  24. ?>