-
-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Description
Hello! In the RedisCacheEngine class's clear method, line 162 uses the keys method to retrieve all keys by mask. Keys isn't performant; you should use ->scan to search by mask.
The main reasons against Keys are:
- It locks Redis for the entire execution time.
- It's O(N) complex - the more keys, the longer the lock.
- With large databases, it can lead to timeouts and errors.
- It's a production anti-pattern.
/**
* @throws NotFoundExceptionInterface
* @throws InvalidArgumentException
* @throws RedisException
* @throws ContainerExceptionInterface
*/
#[\Override]
public function clear(): bool
{
$keys = $this->redis->keys('cache:*');
foreach ($keys as $key) {
if (preg_match('/^cache:(?<key>.*)/', $key, $matches)) {
$this->delete($matches['key']);
}
}
return true;
}Metadata
Metadata
Assignees
Labels
No labels