MultipleSetAndGet.php 540 B

1234567891011121314151617181920212223242526272829
  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 = Predis\Client::create($configurations);
  12. $redis->mset($mkv);
  13. $retval = $redis->mget(array_keys($mkv));
  14. print_r($retval);
  15. /* OUTPUT:
  16. Array
  17. (
  18. [0] => First user
  19. [1] => Second user
  20. [2] => Third user
  21. )
  22. */
  23. ?>