HashScan.php 1.8 KB

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