Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 22 additions & 9 deletions lib/private/Memcache/Redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,29 @@

#[\Override]
public function clear($prefix = '') {
// TODO: this is slow and would fail with Redis cluster
$prefix = $this->getPrefix() . $prefix . '*';
/** @var list<string>|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);

Check failure on line 108 in lib/private/Memcache/Redis.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

InvalidScalarArgument

lib/private/Memcache/Redis.php:108:57: InvalidScalarArgument: Argument 3 of RedisCluster::scan expects null|string, but 1000 provided (see https://psalm.dev/012)
if ($keys === false) {
break;
}

if (!empty($keys)) {
$expectedTotal += count($keys);
$result = $this->getCache()->del($keys);

Check failure on line 115 in lib/private/Memcache/Redis.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

InvalidScalarArgument

lib/private/Memcache/Redis.php:115:38: InvalidScalarArgument: Argument 1 of Redis::del expects array<array-key, mixed>|string, but non-empty-array<array-key, mixed>|true provided (see https://psalm.dev/012)

Check failure on line 115 in lib/private/Memcache/Redis.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

InvalidScalarArgument

lib/private/Memcache/Redis.php:115:38: InvalidScalarArgument: Argument 1 of RedisCluster::del expects array<array-key, mixed>|string, but non-empty-array<array-key, mixed>|true provided (see https://psalm.dev/012)
if (is_int($result)) {
$deletedTotal += $result;
}
}

if ($iterator === 0) {
break;
}
}

$deleted = $this->getCache()->del($keys);
return count($keys) === $deleted;
return $deletedTotal === $expectedTotal;
}

#[\Override]
Expand Down
Loading