StringSetMultiple.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. class StringSetMultiple extends Command
  12. {
  13. public function getId()
  14. {
  15. return 'MSET';
  16. }
  17. protected function filterArguments(Array $arguments)
  18. {
  19. if (count($arguments) === 1 && is_array($arguments[0])) {
  20. $flattenedKVs = array();
  21. $args = $arguments[0];
  22. foreach ($args as $k => $v) {
  23. $flattenedKVs[] = $k;
  24. $flattenedKVs[] = $v;
  25. }
  26. return $flattenedKVs;
  27. }
  28. return $arguments;
  29. }
  30. protected function onPrefixKeys(Array $arguments, $prefix)
  31. {
  32. $length = count($arguments);
  33. for ($i = 0; $i < $length; $i += 2) {
  34. $arguments[$i] = "$prefix{$arguments[$i]}";
  35. }
  36. return $arguments;
  37. }
  38. protected function canBeHashed()
  39. {
  40. $args = $this->getArguments();
  41. $keys = array();
  42. for ($i = 0; $i < count($args); $i += 2) {
  43. $keys[] = $args[$i];
  44. }
  45. return $this->checkSameHashForKeys($keys);
  46. }
  47. }