Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4cc1006

Browse files
committed
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 ------- 178506e Fix getItems() performance issue with RedisCluster (php-redis)
2 parents 83fec23 + 178506e commit 4cc1006

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/Symfony/Component/Cache/Traits/RedisTrait.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,18 +169,29 @@ public static function createConnection($dsn, array $options = [])
169169
*/
170170
protected function doFetch(array $ids)
171171
{
172-
if ($ids) {
172+
if (!$ids) {
173+
return [];
174+
}
175+
176+
$result = [];
177+
178+
if ($this->redis instanceof \Predis\Client && $this->redis->getConnection() instanceof ClusterInterface) {
173179
$values = $this->pipeline(function () use ($ids) {
174180
foreach ($ids as $id) {
175181
yield 'get' => [$id];
176182
}
177183
});
178-
foreach ($values as $id => $v) {
179-
if ($v) {
180-
yield $id => parent::unserialize($v);
181-
}
184+
} else {
185+
$values = array_combine($ids, $this->redis->mget($ids));
186+
}
187+
188+
foreach ($values as $id => $v) {
189+
if ($v) {
190+
$result[$id] = parent::unserialize($v);
182191
}
183192
}
193+
194+
return $result;
184195
}
185196

186197
/**

0 commit comments

Comments
 (0)