Skip to content

Commit

Permalink
TASK: Replace use of KEYS with SCAN in flush()
Browse files Browse the repository at this point in the history
This should speed up flush operations and lower the load on Redis.
  • Loading branch information
kdambekalns committed Aug 29, 2024
1 parent 4b6fdb0 commit 48381d2
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions Neos.Cache/Classes/Backend/RedisBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,15 @@ public function flush(): void
{
// language=lua
$script = "
local keys = redis.call('KEYS', ARGV[1] .. '*')
for k1,key in ipairs(keys) do
redis.call('DEL', key)
end
local cursor = '0'
repeat
local result = redis.call('SCAN', cursor, 'MATCH', ARGV[1] .. '*')
cursor = result[1]
local keys = result[2]
for _, key in ipairs(keys) do
redis.call('DEL', key)
end
until cursor == '0'
";
$this->redis->eval($script, [$this->getPrefixedIdentifier('')], 0);

Expand Down

0 comments on commit 48381d2

Please sign in to comment.