ZSetScan.php 1.9 KB

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