MultipleSetAndGet.php 762 B

12345678910111213141516171819202122232425262728293031323334353637
  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. var_export($retval);
  23. /* OUTPUT:
  24. array (
  25. 0 => 'First user',
  26. 1 => 'Second user',
  27. 2 => 'Third user',
  28. )
  29. */