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); }
/** * Remove specified keys. * * @param string|array $keys * * @return int Number of keys deleted. * @link http://redis.io/commands/del * @example * <pre> * $redis->set('key1', 'val1'); * $redis->set('key2', 'val2'); * $redis->set('key3', 'val3'); * $redis->set('key4', 'val4'); * $redis->delete('key1'); // return 1 * $redis->delete('key3', 'key4'); // return 2 * </pre> */ public function del($keys) { try { return $this->client->del($keys); } catch (Exception $e) { return $this->handleException($e, __FUNCTION__, func_get_args()); } }
/** * Deletes array of keys or key from cache and redis db * * @param array|string $keys * @return int */ private function cachedDel($keys) { if (is_array($keys)) { foreach ($keys as $key) { unset($this->cache[$key]); } } else { if (is_string($keys)) { unset($this->cache[$keys]); } } return $this->redis->del($keys); }
/** * Remove specified keys. * * @param string|array $keys * * @return int Number of keys deleted. * @link http://redis.io/commands/del * @example * <pre> * $redis->set('key1', 'val1'); * $redis->set('key2', 'val2'); * $redis->set('key3', 'val3'); * $redis->set('key4', 'val4'); * $redis->delete('key1'); // return 1 * $redis->delete('key3', 'key4'); // return 2 * </pre> */ public function del($keys) { $this->appendToLog('DEL ' . $this->keysToString($keys)); return $this->client->del($keys); }