diff --git a/src/Symfony/Component/Cache/Adapter/AbstractTagAwareAdapter.php b/src/Symfony/Component/Cache/Adapter/AbstractTagAwareAdapter.php index 5e535e51fcb4b..13a4968ac596d 100644 --- a/src/Symfony/Component/Cache/Adapter/AbstractTagAwareAdapter.php +++ b/src/Symfony/Component/Cache/Adapter/AbstractTagAwareAdapter.php @@ -229,10 +229,14 @@ public function deleteItems(array $keys) unset($this->deferred[$key]); } - foreach ($this->doFetch($ids) as $id => $value) { - foreach ($value['tags'] ?? [] as $tag) { - $tagData[$this->getId(self::TAGS_PREFIX.$tag)][] = $id; + try { + foreach ($this->doFetch($ids) as $id => $value) { + foreach ($value['tags'] ?? [] as $tag) { + $tagData[$this->getId(self::TAGS_PREFIX.$tag)][] = $id; + } } + } catch (\Exception $e) { + // ignore unserialization failures } try { diff --git a/src/Symfony/Component/Cache/Adapter/RedisTagAwareAdapter.php b/src/Symfony/Component/Cache/Adapter/RedisTagAwareAdapter.php index 3bc5d84b62eab..b83b09b013dee 100644 --- a/src/Symfony/Component/Cache/Adapter/RedisTagAwareAdapter.php +++ b/src/Symfony/Component/Cache/Adapter/RedisTagAwareAdapter.php @@ -97,7 +97,7 @@ protected function doSave(array $values, ?int $lifetime, array $addTagData = [], } // While pipeline isn't supported on RedisCluster, other setups will at least benefit from doing this in one op - $results = $this->pipeline(static function () use ($serialized, $lifetime, $addTagData, $delTagData) { + $results = $this->pipeline(static function () use ($serialized, $lifetime, $addTagData, $delTagData, $failed) { // Store cache items, force a ttl if none is set, as there is no MSETEX we need to set each one foreach ($serialized as $id => $value) { yield 'setEx' => [ @@ -109,11 +109,15 @@ protected function doSave(array $values, ?int $lifetime, array $addTagData = [], // Add and Remove Tags foreach ($addTagData as $tagId => $ids) { - yield 'sAdd' => array_merge([$tagId], $ids); + if (!$failed || $ids = array_diff($ids, $failed)) { + yield 'sAdd' => array_merge([$tagId], $ids); + } } foreach ($delTagData as $tagId => $ids) { - yield 'sRem' => array_merge([$tagId], $ids); + if (!$failed || $ids = array_diff($ids, $failed)) { + yield 'sRem' => array_merge([$tagId], $ids); + } } });