Exemplo n.º 1
0
 public function testSScan()
 {
     $this->redis->del('testSScan');
     $key = 'testSScan';
     $members = ['testScan', 'testScanHello', 'testScanHallo', 'testScanHaallo', 'testScanHoula', 'testScan2', 'testScanHello2', 'testScanHallo2', 'testScanHaallo2', 'testScanHoula2', 'testScan3', 'testScanHello3', 'testScanHallo3', 'testScanHaallo3', 'testScanHoula3'];
     $this->redis->sAdd($key, $members);
     // a bit tricky to test, since we can't determine the outcome of a single iteration (or can we?)
     // so we just iterate until the iterator is exhausted and then compare the final results
     $iterator = 0;
     // we unroll the iteration here, to have better control over the involved values
     $result = $this->redis->sScan($key, $iterator);
     $this->assertNotEmpty($result);
     $this->assertNotSame(0, $iterator);
     $result = array_merge($result, $this->redis->sScan($key, $iterator));
     foreach ($members as $member) {
         $this->assertContains($member, $result);
     }
     $this->assertSame(15, count($result));
     $this->assertSame(0, $iterator);
     $smembers = $this->redis->sMembers($key);
     sort($smembers);
     sort($result);
     $this->assertSame($smembers, $result);
     $result1 = $this->redis->sScan($key, $iterator, 'testScanH?llo', 20);
     $this->assertContains('testScanHello', $result1);
     $this->assertContains('testScanHallo', $result1);
     $this->assertEquals(2, count($result1));
     $this->assertSame(0, $iterator);
 }