Skip to content

Commit

Permalink
bug #23237 [Cache] Fix Predis client cluster with pipeline (flolivaud)
Browse files Browse the repository at this point in the history
This PR was merged into the 3.3 branch.

Discussion
----------

[Cache] Fix Predis client cluster with pipeline

| Q             | A
| ------------- | ---
| Branch?       | 3.3
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | n/a
| License       | MIT
| Doc PR        | n/a

Commits
-------

a85d5b0 Fix Predis client cluster with pipeline
  • Loading branch information
fabpot committed Jun 21, 2017
2 parents 383c6ac + a85d5b0 commit 7bb72b0
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/Symfony/Component/Cache/Traits/RedisTrait.php
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Component\Cache\Traits;

use Predis\Connection\Factory;
use Predis\Connection\Aggregate\ClusterInterface;
use Predis\Connection\Aggregate\PredisCluster;
use Predis\Connection\Aggregate\RedisCluster;
use Predis\Response\Status;
Expand Down Expand Up @@ -284,7 +285,7 @@ private function pipeline(\Closure $generator)
{
$ids = array();

if ($this->redis instanceof \Predis\Client) {
if ($this->redis instanceof \Predis\Client && !$this->redis->getConnection() instanceof ClusterInterface) {
$results = $this->redis->pipeline(function ($redis) use ($generator, &$ids) {
foreach ($generator() as $command => $args) {
call_user_func_array(array($redis, $command), $args);
Expand All @@ -308,9 +309,10 @@ private function pipeline(\Closure $generator)
foreach ($results as $k => list($h, $c)) {
$results[$k] = $connections[$h][$c];
}
} elseif ($this->redis instanceof \RedisCluster) {
// phpredis doesn't support pipelining with RedisCluster
} elseif ($this->redis instanceof \RedisCluster || ($this->redis instanceof \Predis\Client && $this->redis->getConnection() instanceof ClusterInterface)) {
// phpredis & predis don't support pipelining with RedisCluster
// see https://github.com/phpredis/phpredis/blob/develop/cluster.markdown#pipelining
// see https://github.com/nrk/predis/issues/267#issuecomment-123781423
$results = array();
foreach ($generator() as $command => $args) {
$results[] = call_user_func_array(array($this->redis, $command), $args);
Expand Down

0 comments on commit 7bb72b0

Please sign in to comment.