Skip to content

Commit fd8cee6

Browse files
bug #54816 [Cache] Fix support for predis/predis:^2.0 (mfettig)
This PR was merged into the 5.4 branch. Discussion ---------- [Cache] Fix support for predis/predis:^2.0 | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | - | License | MIT This PR backports #49801 to 5.4. That's the best way to fix the remaining deprecations. Commits ------- 5ab2d90 [Cache] Fix support for predis/predis:^2.0
2 parents 963b29d + 5ab2d90 commit fd8cee6

File tree

7 files changed

+15
-10
lines changed

7 files changed

+15
-10
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@
138138
"php-http/httplug": "^1.0|^2.0",
139139
"php-http/message-factory": "^1.0",
140140
"phpstan/phpdoc-parser": "^1.0",
141-
"predis/predis": "~1.1",
141+
"predis/predis": "^1.1|^2.0",
142142
"psr/http-client": "^1.0",
143143
"psr/simple-cache": "^1.0|^2.0",
144144
"egulias/email-validator": "^2.1.10|^3.1|^4",

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
use Predis\Connection\Aggregate\ClusterInterface;
1616
use Predis\Connection\Aggregate\RedisCluster;
1717
use Predis\Connection\Aggregate\ReplicationInterface;
18+
use Predis\Connection\Cluster\ClusterInterface as Predis2ClusterInterface;
19+
use Predis\Connection\Cluster\RedisCluster as Predis2RedisCluster;
1820
use Predis\Response\ErrorInterface;
1921
use Predis\Response\Status;
2022
use Symfony\Component\Cache\Exception\CacheException;
@@ -414,7 +416,7 @@ protected function doFetch(array $ids)
414416

415417
$result = [];
416418

417-
if ($this->redis instanceof \Predis\ClientInterface && $this->redis->getConnection() instanceof ClusterInterface) {
419+
if ($this->redis instanceof \Predis\ClientInterface && ($this->redis->getConnection() instanceof ClusterInterface || $this->redis->getConnection() instanceof Predis2ClusterInterface)) {
418420
$values = $this->pipeline(function () use ($ids) {
419421
foreach ($ids as $id) {
420422
yield 'get' => [$id];
@@ -511,7 +513,7 @@ protected function doDelete(array $ids)
511513
return true;
512514
}
513515

514-
if ($this->redis instanceof \Predis\ClientInterface && $this->redis->getConnection() instanceof ClusterInterface) {
516+
if ($this->redis instanceof \Predis\ClientInterface && ($this->redis->getConnection() instanceof ClusterInterface || $this->redis->getConnection() instanceof Predis2ClusterInterface)) {
515517
static $del;
516518
$del = $del ?? (class_exists(UNLINK::class) ? 'unlink' : 'del');
517519

@@ -569,7 +571,7 @@ private function pipeline(\Closure $generator, ?object $redis = null): \Generato
569571
$ids = [];
570572
$redis = $redis ?? $this->redis;
571573

572-
if ($redis instanceof RedisClusterProxy || $redis instanceof \RedisCluster || ($redis instanceof \Predis\ClientInterface && $redis->getConnection() instanceof RedisCluster)) {
574+
if ($redis instanceof RedisClusterProxy || $redis instanceof \RedisCluster || ($redis instanceof \Predis\ClientInterface && ($redis->getConnection() instanceof RedisCluster || $redis->getConnection() instanceof Predis2RedisCluster))) {
573575
// phpredis & predis don't support pipelining with RedisCluster
574576
// see https://github.com/phpredis/phpredis/blob/develop/cluster.markdown#pipelining
575577
// see https://github.com/nrk/predis/issues/267#issuecomment-123781423
@@ -631,7 +633,7 @@ private function getHosts(): array
631633
$hosts = [$this->redis];
632634
if ($this->redis instanceof \Predis\ClientInterface) {
633635
$connection = $this->redis->getConnection();
634-
if ($connection instanceof ClusterInterface && $connection instanceof \Traversable) {
636+
if (($connection instanceof ClusterInterface || $connection instanceof Predis2ClusterInterface) && $connection instanceof \Traversable) {
635637
$hosts = [];
636638
foreach ($connection as $c) {
637639
$hosts[] = new \Predis\Client($c);

src/Symfony/Component/Cache/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"cache/integration-tests": "dev-master",
3636
"doctrine/cache": "^1.6|^2.0",
3737
"doctrine/dbal": "^2.13.1|^3|^4",
38-
"predis/predis": "^1.1",
38+
"predis/predis": "^1.1|^2.0",
3939
"psr/simple-cache": "^1.0|^2.0",
4040
"symfony/config": "^4.4|^5.0|^6.0",
4141
"symfony/dependency-injection": "^4.4|^5.0|^6.0",

src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/PredisClusterSessionHandlerTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ class PredisClusterSessionHandlerTest extends AbstractRedisSessionHandlerTestCas
2323
*/
2424
protected function createRedisClient(string $host): object
2525
{
26-
return new Client([array_combine(['host', 'port'], explode(':', getenv('REDIS_HOST')) + [1 => 6379])]);
26+
return new Client(
27+
[array_combine(['host', 'port'], explode(':', getenv('REDIS_HOST')) + [1 => 6379])],
28+
['cluster' => 'redis']
29+
);
2730
}
2831
}

src/Symfony/Component/HttpFoundation/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"symfony/polyfill-php80": "^1.16"
2323
},
2424
"require-dev": {
25-
"predis/predis": "~1.0",
25+
"predis/predis": "^1.0|^2.0",
2626
"symfony/cache": "^4.4|^5.0|^6.0",
2727
"symfony/dependency-injection": "^5.4|^6.0",
2828
"symfony/http-kernel": "^5.4.12|^6.0.12|^6.1.4",

src/Symfony/Component/Lock/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
},
2424
"require-dev": {
2525
"doctrine/dbal": "^2.13|^3|^4",
26-
"predis/predis": "~1.0"
26+
"predis/predis": "^1.0|^2.0"
2727
},
2828
"conflict": {
2929
"doctrine/dbal": "<2.13"

src/Symfony/Component/Semaphore/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"psr/log": "^1|^2|^3"
2525
},
2626
"require-dev": {
27-
"predis/predis": "~1.0"
27+
"predis/predis": "^1.1|^2.0"
2828
},
2929
"autoload": {
3030
"psr-4": { "Symfony\\Component\\Semaphore\\": "" },

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy