MultipleSetAndGet.php 762 B

1234567891011121314151617181920212223242526272829303132333435363738
  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. // redis can set keys and their relative values in one go
  12. // using MSET, then the same values can be retrieved with
  13. // a single command using MGET.
  14. $mkv = array(
  15. 'usr:0001' => 'First user',
  16. 'usr:0002' => 'Second user',
  17. 'usr:0003' => 'Third user'
  18. );
  19. $client = new Predis\Client($single_server);
  20. $client->mset($mkv);
  21. $retval = $client->mget(array_keys($mkv));
  22. print_r($retval);
  23. /* OUTPUT:
  24. Array
  25. (
  26. [0] => First user
  27. [1] => Second user
  28. [2] => Third user
  29. )
  30. */