diff --git a/lib/private/Memcache/Redis.php b/lib/private/Memcache/Redis.php index 9c8eb4aaee979..2ebe7a2634866 100644 --- a/lib/private/Memcache/Redis.php +++ b/lib/private/Memcache/Redis.php @@ -100,16 +100,29 @@ public function remove($key): bool { #[\Override] public function clear($prefix = '') { - // TODO: this is slow and would fail with Redis cluster - $prefix = $this->getPrefix() . $prefix . '*'; - /** @var list|false -- we are not in MULTI mode, so we can cast the return value here */ - $keys = $this->getCache()->keys($prefix); - if ($keys === false) { - return false; + $pattern = $this->getPrefix() . $prefix . '*'; + $deletedTotal = 0; + $expectedTotal = 0; + $iterator = null; + while (true) { + $keys = $this->getCache()->scan($iterator, $pattern, 1000); + if ($keys === false) { + break; + } + + if (!empty($keys)) { + $expectedTotal += count($keys); + $result = $this->getCache()->del($keys); + if (is_int($result)) { + $deletedTotal += $result; + } + } + + if ($iterator === 0) { + break; + } } - - $deleted = $this->getCache()->del($keys); - return count($keys) === $deleted; + return $deletedTotal === $expectedTotal; } #[\Override]