SetScan.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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/sscan
  13. * @author Daniele Alessandri <suppakilla@gmail.com>
  14. */
  15. class SetScan extends PrefixableCommand
  16. {
  17. /**
  18. * {@inheritdoc}
  19. */
  20. public function getId()
  21. {
  22. return 'SSCAN';
  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. * @return array
  40. */
  41. protected function prepareOptions($options)
  42. {
  43. $options = array_change_key_case($options, CASE_UPPER);
  44. $normalized = array();
  45. if (!empty($options['MATCH'])) {
  46. $normalized[] = 'MATCH';
  47. $normalized[] = $options['MATCH'];
  48. }
  49. if (!empty($options['COUNT'])) {
  50. $normalized[] = 'COUNT';
  51. $normalized[] = $options['COUNT'];
  52. }
  53. return $normalized;
  54. }
  55. /**
  56. * {@inheritdoc}
  57. */
  58. public function parseResponse($data)
  59. {
  60. if (is_array($data)) {
  61. $data[0] = (int) $data[0];
  62. }
  63. return $data;
  64. }
  65. }