You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
bug #19551 [Cache] Use SCAN instead of KEYS with Redis >= 2.8 (nicolas-grekas)
This PR was merged into the 3.1 branch.
Discussion
----------
[Cache] Use SCAN instead of KEYS with Redis >= 2.8
| Q | A
| ------------- | ---
| Branch? | 3.1
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | -
| License | MIT
| Doc PR | -
With #19521 coming, clearing cache keys by prefix is going to be used a lot more often.
Time to fix Redis cache clearing.
Commits
-------
aadeb11 [Cache] Use SCAN instead of KEYS with Redis >= 2.8
if (!version_compare($info['redis_version'], '2.8', '>=')) {
194
202
// As documented in Redis documentation (http://redis.io/commands/keys) using KEYS
195
203
// can hang your server when it is executed against large databases (millions of items).
196
-
// Whenever you hit this scale, it is advised to deploy one Redis database per cache pool
197
-
// instead of using namespaces, so that FLUSHDB is used instead.
198
-
$host->eval("local keys=redis.call('KEYS',ARGV[1]..'*') for i=1,#keys,5000 do redis.call('DEL',unpack(keys,i,math.min(i+4999,#keys))) end", $evalArgs[0], $evalArgs[1]);
204
+
// Whenever you hit this scale, you should really consider upgrading to Redis 2.8 or above.
205
+
$cleared = $host->eval("local keys=redis.call('KEYS',ARGV[1]..'*') for i=1,#keys,5000 do redis.call('DEL',unpack(keys,i,math.min(i+4999,#keys))) end return 1", $evalArgs[0], $evalArgs[1]) && $cleared;
0 commit comments