Skip to content

Commit 76c75b8

Browse files
committed
Refactor Redis driver to read all keys efficiently
The Redis driver's function to read all keys has been streamlined. The changes include removing the check for iterable and adding a loop to scan and merge the keys iteratively. This ensures that the function will work correctly, even when the number of keys retrieved exceeds the MAX_ALL_KEYS_COUNT.
1 parent 372d62e commit 76c75b8

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

lib/Phpfastcache/Drivers/Redis/Driver.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,16 @@ protected function driverConnect(): bool
125125
*/
126126
protected function driverReadAllKeys(string $pattern = '*'): iterable
127127
{
128-
$i = -1;
129-
$keys = $this->instance->scan($i, $pattern === '' ? '*' : $pattern, ExtendedCacheItemPoolInterface::MAX_ALL_KEYS_COUNT);
130-
if (is_iterable($keys)) {
131-
return $keys;
132-
} else {
133-
return [];
134-
}
128+
$i = null;
129+
$keys = [];
130+
$pattern = $pattern === '' ? '*' : $pattern;
131+
do {
132+
$keys = array_merge($keys, $this->instance->scan($i, $pattern));
133+
if (sizeof($keys) > ExtendedCacheItemPoolInterface::MAX_ALL_KEYS_COUNT) {
134+
break;
135+
}
136+
} while ($i > 0);
137+
return $keys;
135138
}
136139

137140
/**

0 commit comments

Comments
 (0)