diff --git a/src/Symfony/Component/Cache/Adapter/RedisTagAwareAdapter.php b/src/Symfony/Component/Cache/Adapter/RedisTagAwareAdapter.php index c721f35d73d4e..b8b4b6f7b3134 100644 --- a/src/Symfony/Component/Cache/Adapter/RedisTagAwareAdapter.php +++ b/src/Symfony/Component/Cache/Adapter/RedisTagAwareAdapter.php @@ -15,6 +15,7 @@ use Predis\Connection\Aggregate\PredisCluster; use Predis\Connection\Aggregate\ReplicationInterface; use Predis\Response\Status; +use Symfony\Component\Cache\CacheItem; use Symfony\Component\Cache\Exception\InvalidArgumentException; use Symfony\Component\Cache\Exception\LogicException; use Symfony\Component\Cache\Marshaller\DeflateMarshaller; @@ -159,6 +160,12 @@ protected function doDeleteYieldTags(array $ids): iterable }); foreach ($results as $id => $result) { + if ($result instanceof \RedisException) { + CacheItem::log($this->logger, 'Failed to delete key "{key}": '.$result->getMessage(), ['key' => substr($id, \strlen($this->namespace)), 'exception' => $result]); + + continue; + } + try { yield $id => !\is_string($result) || '' === $result ? [] : $this->marshaller->unmarshall($result); } catch (\Exception $e) { @@ -197,6 +204,8 @@ protected function doInvalidate(array $tagIds): bool // gargage collect that set from the client side. $lua = <<<'EOLUA' + redis.replicate_commands() + local cursor = '0' local id = KEYS[1] repeat @@ -234,6 +243,8 @@ protected function doInvalidate(array $tagIds): bool }); $lua = <<<'EOLUA' + redis.replicate_commands() + local id = KEYS[1] local cursor = table.remove(ARGV) redis.call('SREM', '{'..id..'}'..id, unpack(ARGV)) @@ -241,7 +252,17 @@ protected function doInvalidate(array $tagIds): bool return redis.call('SSCAN', '{'..id..'}'..id, cursor, 'COUNT', 5000) EOLUA; - foreach ($results as $id => [$cursor, $ids]) { + $success = true; + foreach ($results as $id => $values) { + if ($values instanceof \RedisException) { + CacheItem::log($this->logger, 'Failed to invalidate key "{key}": '.$values->getMessage(), ['key' => substr($id, \strlen($this->namespace)), 'exception' => $values]); + $success = false; + + continue; + } + + [$cursor, $ids] = $values; + while ($ids || '0' !== $cursor) { $this->doDelete($ids); @@ -264,7 +285,7 @@ protected function doInvalidate(array $tagIds): bool } } - return true; + return $success; } private function getRedisEvictionPolicy(): string