1<?php 2 3/* 4 * This file is part of the Predis package. 5 * 6 * (c) Daniele Alessandri <suppakilla@gmail.com> 7 * 8 * For the full copyright and license information, please view the LICENSE 9 * file that was distributed with this source code. 10 */ 11 12namespace Predis\Collection\Iterator; 13 14use Predis\ClientInterface; 15 16/** 17 * Abstracts the iteration of fields and values of an hash by leveraging the 18 * HSCAN command (Redis >= 2.8) wrapped in a fully-rewindable PHP iterator. 19 * 20 * @author Daniele Alessandri <suppakilla@gmail.com> 21 * 22 * @link http://redis.io/commands/scan 23 */ 24class HashKey extends CursorBasedIterator 25{ 26 protected $key; 27 28 /** 29 * {@inheritdoc} 30 */ 31 public function __construct(ClientInterface $client, $key, $match = null, $count = null) 32 { 33 $this->requiredCommand($client, 'HSCAN'); 34 35 parent::__construct($client, $match, $count); 36 37 $this->key = $key; 38 } 39 40 /** 41 * {@inheritdoc} 42 */ 43 protected function executeCommand() 44 { 45 return $this->client->hscan($this->key, $this->cursor, $this->getScanOptions()); 46 } 47 48 /** 49 * {@inheritdoc} 50 */ 51 protected function extractNext() 52 { 53 $this->position = key($this->elements); 54 $this->current = array_shift($this->elements); 55 } 56} 57