KeyPrefixes.php 725 B

12345678910111213141516171819202122232425262728
  1. <?php
  2. require 'SharedConfigurations.php';
  3. // Predis ships with a KeyPrefixProcessor class that is used to transparently
  4. // prefix each key before sending commands to Redis, even for complex commands
  5. // such as SORT, ZUNIONSTORE and ZINTERSTORE. Key prefixes are useful to create
  6. // user-level namespaces for you keyspace, thus eliminating the need for separate
  7. // logical databases.
  8. $client = new Predis\Client($single_server, array('prefix' => 'nrk:'));
  9. $client->mset(array('foo' => 'bar', 'lol' => 'wut'));
  10. var_dump($client->mget('foo', 'lol'));
  11. /*
  12. array(2) {
  13. [0]=> string(3) "bar"
  14. [1]=> string(3) "wut"
  15. }
  16. */
  17. var_dump($client->keys('*'));
  18. /*
  19. array(2) {
  20. [0]=> string(7) "nrk:foo"
  21. [1]=> string(7) "nrk:lol"
  22. }
  23. */