Skip to content

Commit 1e7582b

Browse files
committed
Also rewrite of method driverReadAllKeys in Rediscluster driver.
1 parent 76c75b8 commit 1e7582b

File tree

2 files changed

+19
-18
lines changed

2 files changed

+19
-18
lines changed

lib/Phpfastcache/Drivers/Redis/Driver.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,15 +126,14 @@ protected function driverConnect(): bool
126126
protected function driverReadAllKeys(string $pattern = '*'): iterable
127127
{
128128
$i = null;
129-
$keys = [];
130129
$pattern = $pattern === '' ? '*' : $pattern;
131130
do {
132-
$keys = array_merge($keys, $this->instance->scan($i, $pattern));
133-
if (sizeof($keys) > ExtendedCacheItemPoolInterface::MAX_ALL_KEYS_COUNT) {
131+
$keys[] = $this->instance->scan($i, $pattern);
132+
if (\count($keys) > ExtendedCacheItemPoolInterface::MAX_ALL_KEYS_COUNT) {
134133
break;
135134
}
136135
} while ($i > 0);
137-
return $keys;
136+
return \array_merge([], ...$keys);
138137
}
139138

140139
/**

lib/Phpfastcache/Drivers/Rediscluster/Driver.php

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ public function getStats(): DriverStatistic
6262
trim(<<<EOF
6363
Redis Cluster version v%s, php-ext v%s with %d master nodes and %d slaves connected are up since %s.
6464
For more information see RawData.
65-
EOF),
65+
EOF
66+
),
6667
implode(', ', array_unique(array_column($infos, 'redis_version'))),
6768
\phpversion("redis"),
6869
count($masters),
@@ -123,21 +124,22 @@ protected function driverConnect(): bool
123124
*/
124125
protected function driverReadAllKeys(string $pattern = '*'): iterable
125126
{
126-
$keys = [[]];
127+
$result = [[]];
127128
foreach ($this->instance->_masters() as $master) {
128-
$i = -1;
129-
$result = $this->instance->scan(
130-
$i,
131-
$master,
132-
$pattern === '' ? '*' : $pattern,
133-
ExtendedCacheItemPoolInterface::MAX_ALL_KEYS_COUNT
134-
);
135-
if (is_array($result)) {
136-
$keys[] = $result;
137-
}
129+
$i = null;
130+
$pattern = $pattern === '' ? '*' : $pattern;
131+
do {
132+
$result[] = $this->instance->scan(
133+
$i,
134+
$master,
135+
$pattern,
136+
10);
137+
if (\count($result) > ExtendedCacheItemPoolInterface::MAX_ALL_KEYS_COUNT) {
138+
break;
139+
}
140+
} while ($i > 0);
138141
}
139-
140-
return array_unique(array_merge(...$keys));
142+
return array_unique(\array_merge(...$result));
141143
}
142144

143145
/**

0 commit comments

Comments
 (0)