KeyPrefixes.php 805 B

12345678910111213141516171819202122232425262728293031
  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. use Predis\Commands\Processors\KeyPrefixProcessor;
  9. $client = new Predis\Client();
  10. $client->getProfile()->setProcessor(new KeyPrefixProcessor('nrk:'));
  11. $client->mset(array('foo' => 'bar', 'lol' => 'wut'));
  12. var_dump($client->mget('foo', 'lol'));
  13. /*
  14. array(2) {
  15. [0]=> string(3) "bar"
  16. [1]=> string(3) "wut"
  17. }
  18. */
  19. var_dump($client->keys('*'));
  20. /*
  21. array(2) {
  22. [0]=> string(7) "nrk:foo"
  23. [1]=> string(7) "nrk:lol"
  24. }
  25. */