/** * @param $key * @param null $matchPattern * @param int $cnt * * @return \Generator */ public function find($key, $matchPattern = null, $cnt = 1000) { $it = null; $this->client->setOption(\Redis::OPT_SCAN, \Redis::SCAN_RETRY); $redis = $this->client->getRedis(); while ($arr = $redis->sScan($key, $it, $matchPattern, $cnt)) { foreach ($arr as $value) { $cmd = (yield $value); if ($cmd and strtolower($cmd) == 'break') { return; } } } }
/** * @param $keyPattern * @return \Generator */ public function find($keyPattern, $match = null, $cnt = 1000) { $it = null; $this->client->setOption(Redis::OPT_SCAN, Redis::SCAN_RETRY); $redis = $this->client->getRedis(); $keyPattern = $this->ns . $keyPattern; while ($arr_keys = $redis->scan($it, $keyPattern, $cnt)) { foreach ($arr_keys as $key) { $c = str_replace($this->ns, '', $key); $v = $this->get($c); $cmd = (yield $c => $v); if ($cmd and strtolower($cmd) == 'break') { return; } } } }