This iterator tries to emulate the behaviour of cursor-based iterators based on the SCAN-family of commands introduced in Redis <= 2.8, meaning that due to its incremental nature with multiple fetches it can only offer limited guarantees on the returned elements because the collection can change several times (trimmed, deleted, overwritten) during the iteration process.
Автор: Daniele Alessandri (suppakilla@gmail.com)
Наследование: implements Iterator
Пример #1
0
 /**
  * @group disconnected
  */
 public function testIterationRewindable()
 {
     $client = $this->getMock('Predis\\Client', array('getProfile', 'lrange'));
     $client->expects($this->any())->method('getProfile')->will($this->returnValue(ServerProfile::getDefault()));
     $client->expects($this->exactly(2))->method('lrange')->with('key:list', 0, 9)->will($this->returnValue(array('item:1', 'item:2')));
     $iterator = new ListKey($client, 'key:list');
     $iterator->rewind();
     $this->assertTrue($iterator->valid());
     $this->assertSame('item:1', $iterator->current());
     $this->assertSame(0, $iterator->key());
     $iterator->rewind();
     $this->assertTrue($iterator->valid());
     $this->assertSame('item:1', $iterator->current());
     $this->assertSame(0, $iterator->key());
     $iterator->next();
     $this->assertTrue($iterator->valid());
     $this->assertSame(1, $iterator->key());
     $this->assertSame('item:2', $iterator->current());
     $iterator->next();
     $this->assertFalse($iterator->valid());
 }