KeyPrefixProcessor.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. namespace Predis\Commands\Processors;
  11. use Predis\Commands\ICommand;
  12. /**
  13. * Command processor that is used to prefix the keys contained in the arguments
  14. * of a Redis command.
  15. *
  16. * @author Daniele Alessandri <suppakilla@gmail.com>
  17. */
  18. class KeyPrefixProcessor implements ICommandProcessor
  19. {
  20. private $prefix;
  21. /**
  22. * @param string $prefix Prefix for the keys.
  23. */
  24. public function __construct($prefix)
  25. {
  26. $this->setPrefix($prefix);
  27. }
  28. /**
  29. * Sets a prefix that is applied to all the keys.
  30. *
  31. * @param string $prefix Prefix for the keys.
  32. */
  33. public function setPrefix($prefix)
  34. {
  35. $this->prefix = $prefix;
  36. }
  37. /**
  38. * Gets the current prefix.
  39. *
  40. * @return string
  41. */
  42. public function getPrefix()
  43. {
  44. return $this->prefix;
  45. }
  46. /**
  47. * {@inheritdoc}
  48. */
  49. public function process(ICommand $command)
  50. {
  51. $command->prefixKeys($this->prefix);
  52. }
  53. }