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); }
/** * See scan(). * * @link http://redis.io/commands/sscan * * @param string $key the set to iterate over * @param int $iterator a reference to the cursor * @param string $pattern a pattern that the set membershave to match * @param int $count the number of set members to return * @return string[] */ public function sScan($key, &$iterator, $pattern = '', $count = 10) { try { return $this->client->sScan($key, $iterator, $pattern, $count); } catch (Exception $e) { $args = func_get_args(); $args[1] =& $iterator; return $this->handleException($e, __FUNCTION__, $args); } }