HashKey.php 1.2 KB

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