public function testZScan()
 {
     $this->redis->del('testZScan');
     $key = 'testZScan';
     $members = ['testScan', 'testScanHello', 'testScanHallo', 'testScanHaallo', 'testScanHoula', 'testScan2', 'testScanHello2', 'testScanHallo2', 'testScanHaallo2', 'testScanHoula2', 'testScan3', 'testScanHello3', 'testScanHallo3', 'testScanHaallo3', 'testScanHoula3'];
     foreach ($members as $member) {
         $this->redis->zAdd($key, 1.0, $member);
     }
     // 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->zScan($key, $iterator);
     $this->assertNotEmpty($result);
     foreach ($members as $member) {
         $this->assertArrayHasKey($member, $result);
     }
     $this->assertSame(15, count($result));
     $this->assertSame(0, $iterator);
     $smembers = $this->redis->zRange($key, 0, 100, true);
     ksort($smembers);
     ksort($result);
     $this->assertSame($smembers, $result);
     $result1 = $this->redis->zScan($key, $iterator, 'testScanH?llo', 20);
     $this->assertArrayHasKey('testScanHello', $result1);
     $this->assertArrayHasKey('testScanHallo', $result1);
     $this->assertEquals(2, count($result1));
     $this->assertSame(0, $iterator);
 }
Beispiel #2
0
 /**
  * See scan().
  *
  * @link http://redis.io/commands/zscan
  *
  * @param string $key the sorted set to iterate over
  * @param int $iterator a reference to the cursor
  * @param string $pattern a pattern that the keys have to match
  * @param int $count the number of keys to return
  * @return string[]
  */
 public function zScan($key, &$iterator, $pattern = '', $count = 10)
 {
     try {
         return $this->client->zScan($key, $iterator, $pattern, $count);
     } catch (Exception $e) {
         $args = func_get_args();
         $args[1] =& $iterator;
         return $this->handleException($e, __FUNCTION__, $args);
     }
 }