ZSetRangeByScore.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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\Command;
  11. /**
  12. * @link http://redis.io/commands/zrangebyscore
  13. * @author Daniele Alessandri <suppakilla@gmail.com>
  14. */
  15. class ZSetRangeByScore extends ZSetRange
  16. {
  17. /**
  18. * {@inheritdoc}
  19. */
  20. public function getId()
  21. {
  22. return 'ZRANGEBYSCORE';
  23. }
  24. /**
  25. * {@inheritdoc}
  26. */
  27. protected function prepareOptions($options)
  28. {
  29. $opts = array_change_key_case($options, CASE_UPPER);
  30. $finalizedOpts = array();
  31. if (isset($opts['LIMIT']) && is_array($opts['LIMIT'])) {
  32. $limit = array_change_key_case($opts['LIMIT'], CASE_UPPER);
  33. $finalizedOpts[] = 'LIMIT';
  34. $finalizedOpts[] = isset($limit['OFFSET']) ? $limit['OFFSET'] : $limit[0];
  35. $finalizedOpts[] = isset($limit['COUNT']) ? $limit['COUNT'] : $limit[1];
  36. }
  37. return array_merge($finalizedOpts, parent::prepareOptions($options));
  38. }
  39. /**
  40. * {@inheritdoc}
  41. */
  42. protected function withScores()
  43. {
  44. $arguments = $this->getArguments();
  45. for ($i = 3; $i < count($arguments); $i++) {
  46. switch (strtoupper($arguments[$i])) {
  47. case 'WITHSCORES':
  48. return true;
  49. case 'LIMIT':
  50. $i += 2;
  51. break;
  52. }
  53. }
  54. return false;
  55. }
  56. }