SortedSetKey.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 members stored in a sorted set
  14. * by leveraging the ZSCAN command (Redis >= 2.8) wrapped in
  15. * a fully-rewindable PHP iterator.
  16. *
  17. * @author Daniele Alessandri <suppakilla@gmail.com>
  18. * @link http://redis.io/commands/scan
  19. */
  20. class SortedSetKey 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, 'ZSCAN');
  29. parent::__construct($client, $match, $count);
  30. $this->key = $key;
  31. }
  32. /**
  33. * {@inheritdoc}
  34. */
  35. protected function executeCommand()
  36. {
  37. return $this->client->zscan($this->key, $this->cursor, $this->getScanOptions());
  38. }
  39. /**
  40. * {@inheritdoc}
  41. */
  42. protected function extractNext()
  43. {
  44. $element = array_shift($this->elements);
  45. $this->position = $element[0];
  46. $this->current = $element[1];
  47. }
  48. }