ZSetRangeByScore.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 ZSetRangeByScore extends ZSetRange
  12. {
  13. public function getId()
  14. {
  15. return 'ZRANGEBYSCORE';
  16. }
  17. protected function prepareOptions($options)
  18. {
  19. $opts = array_change_key_case($options, CASE_UPPER);
  20. $finalizedOpts = array();
  21. if (isset($opts['LIMIT']) && is_array($opts['LIMIT'])) {
  22. $limit = array_change_key_case($opts['LIMIT'], CASE_UPPER);
  23. $finalizedOpts[] = 'LIMIT';
  24. $finalizedOpts[] = isset($limit['OFFSET']) ? $limit['OFFSET'] : $limit[0];
  25. $finalizedOpts[] = isset($limit['COUNT']) ? $limit['COUNT'] : $limit[1];
  26. }
  27. return array_merge($finalizedOpts, parent::prepareOptions($options));
  28. }
  29. protected function withScores()
  30. {
  31. $arguments = $this->getArguments();
  32. for ($i = 3; $i < count($arguments); $i++) {
  33. switch (strtoupper($arguments[$i])) {
  34. case 'WITHSCORES':
  35. return true;
  36. case 'LIMIT':
  37. $i += 2;
  38. break;
  39. }
  40. }
  41. return false;
  42. }
  43. }