KeyPrefixes.php 959 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. // Predis ships with a KeyPrefixProcessor class that is used to transparently
  12. // prefix each key before sending commands to Redis, even for complex commands
  13. // such as SORT, ZUNIONSTORE and ZINTERSTORE. Key prefixes are useful to create
  14. // user-level namespaces for you keyspace, thus eliminating the need for separate
  15. // logical databases.
  16. $client = new Predis\Client($single_server, array('prefix' => 'nrk:'));
  17. $client->mset(array('foo' => 'bar', 'lol' => 'wut'));
  18. var_dump($client->mget('foo', 'lol'));
  19. /*
  20. array(2) {
  21. [0]=> string(3) "bar"
  22. [1]=> string(3) "wut"
  23. }
  24. */
  25. var_dump($client->keys('*'));
  26. /*
  27. array(2) {
  28. [0]=> string(7) "nrk:foo"
  29. [1]=> string(7) "nrk:lol"
  30. }
  31. */