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);
 }
Example #2
0
 /**
  * Returns a range of elements from the ordered set stored at the specified key,
  * with values in the range [start, end]. start and stop are interpreted as zero-based indices:
  * 0 the first element,
  * 1 the second ...
  * -1 the last element,
  * -2 the penultimate ...
  *
  * @param string $key
  * @param int $start
  * @param int $end
  * @param bool $withscores optional
  *
  * @return array Array containing the values in specified range.
  * @link http://redis.io/commands/zrange
  * @example
  * <pre>
  * $redis->zAdd('key1', 0, 'val0');
  * $redis->zAdd('key1', 2, 'val2');
  * $redis->zAdd('key1', 10, 'val10');
  * $redis->zRange('key1', 0, -1); // array('val0', 'val2', 'val10')
  * // with scores
  * $redis->zRange('key1', 0, -1, true); // array('val0' => 0, 'val2' => 2, 'val10' => 10)
  * </pre>
  */
 public function zRange($key, $start, $end, $withscores = false)
 {
     try {
         return $this->client->zRange($key, $start, $end, $withscores);
     } catch (Exception $e) {
         return $this->handleException($e, __FUNCTION__, func_get_args());
     }
 }
Example #3
0
 /**
  * Returns a range of elements from the ordered set stored at the specified key,
  * with values in the range [start, end]. start and stop are interpreted as zero-based indices:
  * 0 the first element,
  * 1 the second ...
  * -1 the last element,
  * -2 the penultimate ...
  *
  * @param string $key
  * @param int $start
  * @param int $end
  * @param bool $withscores optional
  *
  * @return array Array containing the values in specified range.
  * @link http://redis.io/commands/zrange
  * @example
  * <pre>
  * $redis->zAdd('key1', 0, 'val0');
  * $redis->zAdd('key1', 2, 'val2');
  * $redis->zAdd('key1', 10, 'val10');
  * $redis->zRange('key1', 0, -1); // array('val0', 'val2', 'val10')
  * // with scores
  * $redis->zRange('key1', 0, -1, true); // array('val0' => 0, 'val2' => 2, 'val10' => 10)
  * </pre>
  */
 public function zRange($key, $start, $end, $withscores = false)
 {
     $this->appendToLog('ZRANGE ' . $key . ' ' . $start . ' ' . $end . ($withscores ? ' WITHSCORES' : null));
     return $this->client->zRange($key, $start, $end, $withscores);
 }