StringSetMultiple.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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
  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. protected function onPrefixKeys(Array $arguments, $prefix)
  44. {
  45. $length = count($arguments);
  46. for ($i = 0; $i < $length; $i += 2) {
  47. $arguments[$i] = "$prefix{$arguments[$i]}";
  48. }
  49. return $arguments;
  50. }
  51. /**
  52. * {@inheritdoc}
  53. */
  54. protected function canBeHashed()
  55. {
  56. $args = $this->getArguments();
  57. $keys = array();
  58. for ($i = 0; $i < count($args); $i += 2) {
  59. $keys[] = $args[$i];
  60. }
  61. return $this->checkSameHashForKeys($keys);
  62. }
  63. }