ZSCAN.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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\Redis;
  11. use Predis\Command\Command as RedisCommand;
  12. /**
  13. * @link http://redis.io/commands/zscan
  14. *
  15. * @author Daniele Alessandri <suppakilla@gmail.com>
  16. */
  17. class ZSCAN extends RedisCommand
  18. {
  19. /**
  20. * {@inheritdoc}
  21. */
  22. public function getId()
  23. {
  24. return 'ZSCAN';
  25. }
  26. /**
  27. * {@inheritdoc}
  28. */
  29. public function setArguments(array $arguments)
  30. {
  31. if (count($arguments) === 3 && is_array($arguments[2])) {
  32. $options = $this->prepareOptions(array_pop($arguments));
  33. $arguments = array_merge($arguments, $options);
  34. }
  35. parent::setArguments($arguments);
  36. }
  37. /**
  38. * Returns a list of options and modifiers compatible with Redis.
  39. *
  40. * @param array $options List of options.
  41. *
  42. * @return array
  43. */
  44. protected function prepareOptions($options)
  45. {
  46. $options = array_change_key_case($options, CASE_UPPER);
  47. $normalized = array();
  48. if (!empty($options['MATCH'])) {
  49. $normalized[] = 'MATCH';
  50. $normalized[] = $options['MATCH'];
  51. }
  52. if (!empty($options['COUNT'])) {
  53. $normalized[] = 'COUNT';
  54. $normalized[] = $options['COUNT'];
  55. }
  56. return $normalized;
  57. }
  58. /**
  59. * {@inheritdoc}
  60. */
  61. public function parseResponse($data)
  62. {
  63. if (is_array($data)) {
  64. $members = $data[1];
  65. $result = array();
  66. for ($i = 0; $i < count($members); ++$i) {
  67. $result[$members[$i]] = (float) $members[++$i];
  68. }
  69. $data[1] = $result;
  70. }
  71. return $data;
  72. }
  73. }