ZSetUnionStore.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. namespace Predis\Commands;
  3. class ZSetUnionStore extends Command {
  4. protected function canBeHashed() {
  5. $args = $this->getArguments();
  6. return $this->checkSameHashForKeys(
  7. array_merge(array($args[0]), array_slice($args, 2, $args[1]))
  8. );
  9. }
  10. public function getId() { return 'ZUNIONSTORE'; }
  11. public function filterArguments(Array $arguments) {
  12. $options = array();
  13. $argc = count($arguments);
  14. if ($argc > 2 && is_array($arguments[$argc - 1])) {
  15. $options = $this->prepareOptions(array_pop($arguments));
  16. }
  17. if (is_array($arguments[1])) {
  18. $arguments = array_merge(
  19. array($arguments[0], count($arguments[1])),
  20. $arguments[1]
  21. );
  22. }
  23. return array_merge($arguments, $options);
  24. }
  25. private function prepareOptions($options) {
  26. $opts = array_change_key_case($options, CASE_UPPER);
  27. $finalizedOpts = array();
  28. if (isset($opts['WEIGHTS']) && is_array($opts['WEIGHTS'])) {
  29. $finalizedOpts[] = 'WEIGHTS';
  30. foreach ($opts['WEIGHTS'] as $weight) {
  31. $finalizedOpts[] = $weight;
  32. }
  33. }
  34. if (isset($opts['AGGREGATE'])) {
  35. $finalizedOpts[] = 'AGGREGATE';
  36. $finalizedOpts[] = $opts['AGGREGATE'];
  37. }
  38. return $finalizedOpts;
  39. }
  40. }