8000 Fix Redis replication on Redis <5 · symfony/symfony@eb09827 · GitHub
[go: up one dir, main page]

Skip to content

Commit eb09827

Browse files
committed
Fix Redis replication on Redis <5
1 parent 66e8ae9 commit eb09827

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

src/Symfony/Component/Cache/Adapter/RedisTagAwareAdapter.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Predis\Connection\Aggregate\PredisCluster;
1616
use Predis\Connection\Aggregate\ReplicationInterface;
1717
use Predis\Response\Status;
18+
use Symfony\Component\Cache\CacheItem;
1819
use Symfony\Component\Cache\Exception\InvalidArgumentException;
1920
use Symfony\Component\Cache\Exception\LogicException;
2021
use Symfony\Component\Cache\Marshaller\DeflateMarshaller;
@@ -159,6 +160,12 @@ protected function doDeleteYieldTags(array $ids): iterable
159160
});
160161

161162
foreach ($results as $id => $result) {
163+
if ($result instanceof \RedisException) {
164+
CacheItem::log($this->logger, 'Failed to delete key "{key}": '.$result->getMessage(), ['key' => substr($id, \strlen($this->namespace)), 'exception' => $result]);
165+
166+
continue;
167+
}
168+
162169
try {
163170
yield $id => !\is_string($result) || '' === $result ? [] : $this->marshaller->unmarshall($result);
164171
} catch (\Exception $e) {
@@ -197,6 +204,8 @@ protected function doInvalidate(array $tagIds): bool
197204
// gargage collect that set from the client side.
198205

199206
$lua = <<<'EOLUA'
207+
redis.replicate_commands()
208+
200209
local cursor = '0'
201210
local id = KEYS[1]
202211
repeat
@@ -234,14 +243,26 @@ protected function doInvalidate(array $tagIds): bool
234243
});
235244

236245
$lua = <<<'EOLUA'
246+
redis.replicate_commands()
247+
237248
local id = KEYS[1]
238249
local cursor = table.remove(ARGV)
239250
redis.call('SREM', '{'..id..'}'..id, unpack(ARGV))
240251
241252
return redis.call('SSCAN', '{'..id..'}'..id, cursor, 'COUNT', 5000)
242253
EOLUA;
243254

244-
foreach ($results as $id => [$cursor, $ids]) {
255+
$success = true;
256+
foreach ($results as $id => $values) {
257+
if ($values instanceof \RedisException) {
258+
CacheItem::log($this->logger, 'Failed to invalidate key "{key}": '.$result->getMessage(), ['key' => substr($id, \strlen($this->namespace)), 'exception' => $result]);
259+
$success = false;
260+
261+
continue;
262+
}
263+
264+
[$cursor, $ids] = $values;
265+
245266
while ($ids || '0' !== $cursor) {
246267
$this->doDelete($ids);
247268

@@ -264,7 +285,7 @@ protected function doInvalidate(array $tagIds): bool
264285
}
265286
}
266287

267-
return true;
288+
return $success;
268289
}
269290

270291
private function getRedisEvictionPolicy(): string

0 commit comments

Comments
 (0)
0