key_prefixing.php 891B

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 __DIR__.'/shared.php';
  11. // Predis can prefix keys found in commands arguments before sending commands to
  12. // Redis, even for complex commands such as SORT, ZUNIONSTORE and ZINTERSTORE.
  13. // Prefixing keys can be useful to create user-level namespaces for you keyspace
  14. // thus reducing the need for separate logical databases in certain scenarios.
  15. $client = new Predis\Client($single_server, array('prefix' => 'nrk:'));
  16. $client->mset(array('foo' => 'bar', 'lol' => 'wut'));
  17. var_export($client->mget('foo', 'lol'));
  18. /*
  19. array (
  20. 0 => 'bar',
  21. 1 => 'wut',
  22. )
  23. */
  24. var_export($client->keys('*'));
  25. /*
  26. array (
  27. 0 => 'nrk:foo',
  28. 1 => 'nrk:lol',
  29. )
  30. */