Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
bug #34668 [Cache] Make sure we get the correct number of values from…
… redis::mget() (thePanz)

This PR was merged into the 3.4 branch.

Discussion
----------

[Cache] Make sure we get the correct number of values from redis::mget()

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | N/A
| License       | MIT
| Doc PR        | N/A

Redis might not be reachable when invoking `redis->mget($ids)`, the call returns `false` instead of an array.
This change makes sure the return value is properly check, including the correctness of the parameters to invoke  `array_combine($ids, $cacheValues);`.
From the documentation:
> Returns the combined array, FALSE if the number of elements for each array isn't equal.

Commits
-------

685c36c [Cache] Make sure we get the correct number of values from redis::mget()
  • Loading branch information
nicolas-grekas committed Nov 27, 2019
2 parents ed101fb + 685c36c commit f0a6de2
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Symfony/Component/Cache/Traits/RedisTrait.php
Expand Up @@ -179,7 +179,13 @@ protected function doFetch(array $ids)
}
});
} else {
$values = array_combine($ids, $this->redis->mget($ids));
$values = $this->redis->mget($ids);

if (!\is_array($values) || \count($values) !== \count($ids)) {
return [];
}

$values = array_combine($ids, $values);
}

foreach ($values as $id => $v) {
Expand Down

0 comments on commit f0a6de2

Please sign in to comment.