8000 feature #49801 [Cache] Support Redis cluster connections with predis/… · symfony/symfony@3dfec48 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3dfec48

Browse files
feature #49801 [Cache] Support Redis cluster connections with predis/predis:^2.0 (mfettig)
This PR was merged into the 6.3 branch. Discussion ---------- [Cache] Support Redis cluster connections with predis/predis:^2.0 | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | n/a | License | MIT | Doc PR | n/a In v2 of predis/predis some classes related to cluster connections were reorganized. This PR expands the checks in RedisTrait to also work with the new version of Predis. Previous tests appear to cover this change, and I didn't see any updates needed to documentation, etc. but please let me know if I missed anything. I have been running this locally for a couple of days and while my usage has been limited it has been working well so far I did change the composer constraint for predis/predis from tilde to caret which I was a bit hesitant about, but they should be functionally equivalent in this case and it looked like the caret constraint was more standard. Let me know if that is not an appropriate change and I will switch back to the tilde constraint. Commits ------- eaf6f8c [Cache] Support Redis cluster connections with predis/predis:^2.0
2 parents d5423db + eaf6f8c commit 3dfec48

File tree

8 files changed

+16
-10
lines changed

8 files changed

+16
-10
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@
143143
"php-http/httplug": "^1.0|^2.0",
144144
"phpdocumentor/reflection-docblock": "^5.2",
145145
"phpstan/phpdoc-parser": "^1.0",
146-
"predis/predis": "~1.1",
146+
"predis/predis": "^1.1|^2.0",
147147
"psr/http-client": "^1.0",
148148
"psr/simple-cache": "^1.0|^2.0|^3.0",
149149
"symfony/mercure-bundle": "^0.3",

src/Symfony/Component/Cache/CHANGELOG.md

Lines changed: 1 addition 10000 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
---
66

77
* Add support for Relay PHP extension for Redis
8+
* Updates to allow Redis cluster connections using predis/predis:^2.0
89

910
6.1
1011
---

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 Relay\Relay;
@@ -376,7 +378,7 @@ protected function doFetch(array $ids): iterable
376378

377379
$result = [];
378380

379-
if ($this->redis instanceof \Predis\ClientInterface && $this->redis->getConnection() instanceof ClusterInterface) {
381+
if ($this->redis instanceof \Predis\ClientInterface && ($this->redis->getConnection() instanceof ClusterInterface || $this->redis->getConnection() instanceof Predis2ClusterInterface)) {
380382
$values = $this->pipeline(function () use ($ids) {
381383
foreach ($ids as $id) {
382384
yield 'get' => [$id];
@@ -476,7 +478,7 @@ protected function doDelete(array $ids): bool
476478
return true;
477479
}
478480

479-
if ($this->redis instanceof \Predis\ClientInterface && $this->redis->getConnection() instanceof ClusterInterface) {
481+
if ($this->redis instanceof \Predis\ClientInterface && ($this->redis->getConnection() instanceof ClusterInterface || $this->redis->getConnection() instanceof Predis2ClusterInterface)) {
480482
static $del;
481483
$del ??= (class_exists(UNLINK::class) ? 'unlink' : 'del');
482484

@@ -534,7 +536,7 @@ private function pipeline(\Closure $generator, object $redis = null): \Generator
534536
$ids = [];
535537
$redis ??= $this->redis;
536538

537-
if ($redis instanceof \RedisCluster || ($redis instanceof \Predis\ClientInterface && $redis->getConnection() instanceof RedisCluster)) {
539+
if ($redis instanceof \RedisCluster || ($redis instanceof \Predis\ClientInterface && ($redis->getConnection() instanceof RedisCluster || $redis->getConnection() instanceof Predis2RedisCluster))) {
538540
// phpredis & predis don't support pipelining with RedisCluster
539541
// see https://github.com/phpredis/phpredis/blob/develop/cluster.markdown#pipelining
540542
// see https://github.com/nrk/predis/issues/267#issuecomment-123781423
@@ -596,7 +598,7 @@ private function getHosts(): array
596598
$hosts = [$this->redis];
597599
if ($this->redis instanceof \Predis\ClientInterface) {
598600
$connection = $this->redis->getConnection();
599-
if ($connection instanceof ClusterInterface && $connection instanceof \Traversable) {
601+
if (($connection instanceof ClusterInterface || $connection instanceof Predis2ClusterInterface) && $connection instanceof \Traversable) {
600602
$hosts = [];
601603
foreach ($connection as $c) {
602604
$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
@@ -31,7 +31,7 @@
3131
"require-dev": {
3232
"cache/integration-tests": "dev-master",
3333
"doctrine/dbal": "^2.13.1|^3.0",
34-
"predis/predis": "^1.1",
34+
"predis/predis": "^1.1|^2.0",
3535
"psr/simple-cache": "^1.0|^2.0|^3.0",
3636
"symfony/config": "^5.4|^6.0",
3737
"symfony/dependency-injection": "^5.4|^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
@@ -20,6 +20,9 @@ class PredisClusterSessionHandlerTest extends AbstractRedisSessionHandlerTestCas
2020
{
2121
protected function createRedisClient(string $host): Client
2222
{
23-
return new Client([array_combine(['host', 'port'], explode(':', getenv('REDIS_HOST')) + [1 => 6379])]);
23+
return new Client(
24+
[array_combine(['host', 'port'], explode(':', getenv('REDIS_HOST')) + [1 => 6379])],
25+
['cluster' => 'redis']
26+
);
2427
}
2528
}

src/Symfony/Component/HttpFoundation/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.1|^3.0",
26-
"predis/predis": "~1.0",
26+
"predis/predis": "^1.1|^2.0",
2727
"symfony/cache": "^5.4|^6.0",
2828
"symfony/dependency-injection": "^5.4|^6.0",
2929
"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
@@ -22,7 +22,7 @@
2222
},
2323
"require-dev": {
2424
"doctrine/dbal": "^2.13|^3.0",
25-
"predis/predis": "~1.0"
25+
"predis/predis": "^1.1|^2.0"
2626
},
2727
"conflict": {
2828
"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"
5E3C
2525
},
2626
"require-dev": {
27-
"predis/predis": "~1.0"
27+
"predis/predis": "^1.1|^2.0"
2828
},
2929
"conflict": {
3030
"symfony/cache": "<6.2"

0 commit comments

Comments
 (0)
0