StringSetMultiple.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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;
  11. /**
  12. * @link http://redis.io/commands/mset
  13. * @author Daniele Alessandri <suppakilla@gmail.com>
  14. */
  15. class StringSetMultiple extends Command implements IPrefixable
  16. {
  17. /**
  18. * {@inheritdoc}
  19. */
  20. public function getId()
  21. {
  22. return 'MSET';
  23. }
  24. /**
  25. * {@inheritdoc}
  26. */
  27. protected function filterArguments(Array $arguments)
  28. {
  29. if (count($arguments) === 1 && is_array($arguments[0])) {
  30. $flattenedKVs = array();
  31. $args = $arguments[0];
  32. foreach ($args as $k => $v) {
  33. $flattenedKVs[] = $k;
  34. $flattenedKVs[] = $v;
  35. }
  36. return $flattenedKVs;
  37. }
  38. return $arguments;
  39. }
  40. /**
  41. * {@inheritdoc}
  42. */
  43. public function prefixKeys($prefix)
  44. {
  45. PrefixHelpers::interleaved($this, $prefix);
  46. }
  47. /**
  48. * {@inheritdoc}
  49. */
  50. protected function canBeHashed()
  51. {
  52. $args = $this->getArguments();
  53. $keys = array();
  54. for ($i = 0; $i < count($args); $i += 2) {
  55. $keys[] = $args[$i];
  56. }
  57. return $this->checkSameHashForKeys($keys);
  58. }
  59. }