ZSetRangeByScore.php 1.6 KB

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