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); }
/** * Returns the contents of a set. * * @param string $key * * @return array An array of elements, the contents of the set. * @link http://redis.io/commands/smembers * @example * <pre> * $redis->delete('s'); * $redis->sAdd('s', 'a'); * $redis->sAdd('s', 'b'); * $redis->sAdd('s', 'a'); * $redis->sAdd('s', 'c'); * var_dump($redis->sMembers('s')); * //array(3) { * // [0]=> * // string(1) "c" * // [1]=> * // string(1) "a" * // [2]=> * // string(1) "b" * //} * // The order is random and corresponds to redis' own internal representation of the set structure. * </pre> */ public function sMembers($key) { try { return $this->client->sMembers($key); } catch (Exception $e) { return $this->handleException($e, __FUNCTION__, func_get_args()); } }