HashKey.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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\Collection\Iterator;
  11. use Predis\ClientInterface;
  12. /**
  13. * Abstracts the iteration of fields and values of an hash by leveraging the
  14. * HSCAN command (Redis >= 2.8) wrapped in a fully-rewindable PHP iterator.
  15. *
  16. * @author Daniele Alessandri <suppakilla@gmail.com>
  17. * @link http://redis.io/commands/scan
  18. */
  19. class HashKey extends CursorBasedIterator
  20. {
  21. protected $key;
  22. /**
  23. * {@inheritdoc}
  24. */
  25. public function __construct(ClientInterface $client, $key, $match = null, $count = null)
  26. {
  27. $this->requiredCommand($client, 'HSCAN');
  28. parent::__construct($client, $match, $count);
  29. $this->key = $key;
  30. }
  31. /**
  32. * {@inheritdoc}
  33. */
  34. protected function executeCommand()
  35. {
  36. return $this->client->hscan($this->key, $this->cursor, $this->getScanOptions());
  37. }
  38. /**
  39. * {@inheritdoc}
  40. */
  41. protected function extractNext()
  42. {
  43. $this->position = key($this->elements);
  44. $this->current = array_shift($this->elements);
  45. }
  46. }