bug #30351 Fix getItems() performance issue with RedisCluster (php-redis) (andrerom)

This PR was merged into the 3.4 branch.

Discussion
----------

Fix getItems() performance issue with RedisCluster (php-redis)

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | TBD
| License       | MIT

On any kind of multi loads, including tags loading where it's always the case, current code leads to an explosion of Redis lookups affecting performance on RedisCluster _(as it does not support pipeline)_.

This backports the code for mget() usage from 4.x in order to fix it.
It's done with one small improvment which would also be relevant for 4.x, only using pipeline on cluster on predis as mget is more efficient (ref redis doc).

Commits
-------

178506e72c Fix getItems() performance issue with RedisCluster (php-redis)
This commit is contained in:
Fabien Potencier 2019-02-23 12:03:32 +01:00
commit 4cc10062e2
1 changed files with 16 additions and 5 deletions

View File

@ -169,18 +169,29 @@ trait RedisTrait
*/
protected function doFetch(array $ids)
{
if ($ids) {
if (!$ids) {
return [];
}
$result = [];
if ($this->redis instanceof \Predis\Client && $this->redis->getConnection() instanceof ClusterInterface) {
$values = $this->pipeline(function () use ($ids) {
foreach ($ids as $id) {
yield 'get' => [$id];
}
});
foreach ($values as $id => $v) {
if ($v) {
yield $id => parent::unserialize($v);
}
} else {
$values = array_combine($ids, $this->redis->mget($ids));
}
foreach ($values as $id => $v) {
if ($v) {
$result[$id] = parent::unserialize($v);
}
}
return $result;
}
/**