mirror of
https://github.com/codeigniter4/CodeIgniter4.git
synced 2025-02-20 11:44:28 +08:00
refactor RedisHandler::deleteMatching()
This commit is contained in:
parent
9099e20cae
commit
3d5b97d582
@ -175,19 +175,17 @@ class RedisHandler extends BaseHandler
|
||||
*/
|
||||
public function deleteMatching(string $pattern)
|
||||
{
|
||||
/** @var list<string> $matchedKeys */
|
||||
$matchedKeys = [];
|
||||
$pattern = static::validateKey($pattern, $this->prefix);
|
||||
$iterator = null;
|
||||
|
||||
do {
|
||||
// Scan for some keys
|
||||
/** @var false|list<string>|Redis $keys */
|
||||
$keys = $this->redis->scan($iterator, $pattern);
|
||||
|
||||
// Redis may return empty results, so protect against that
|
||||
if ($keys !== false) {
|
||||
foreach ($keys as $key) {
|
||||
$matchedKeys[] = $key;
|
||||
}
|
||||
if (is_array($keys)) {
|
||||
$matchedKeys = [...$matchedKeys, ...$keys];
|
||||
}
|
||||
} while ($iterator > 0);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user