Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 839528b

Browse filesBrowse files
committed
[Messenger] Support RedisCluster instance
1 parent bbc2d6a commit 839528b
Copy full SHA for 839528b

File tree

4 files changed

+36
-5
lines changed
Filter options

4 files changed

+36
-5
lines changed

‎src/Symfony/Component/Messenger/Bridge/Redis/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/Messenger/Bridge/Redis/CHANGELOG.md
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
5.3.0
5+
-----
6+
7+
* Added support for `\RedisCluster` instance in `Connection` constructor
8+
49
5.2.0
510
-----
611

‎src/Symfony/Component/Messenger/Bridge/Redis/Tests/Transport/ConnectionTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Messenger/Bridge/Redis/Tests/Transport/ConnectionTest.php
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ public static function setUpBeforeClass(): void
4040
}
4141
}
4242

43+
private function skipIfRedisClusterUnavailable()
44+
{
45+
try {
46+
new \RedisCluster(null, explode(' ', getenv('REDIS_CLUSTER_HOSTS')));
47+
} catch (\Exception $e) {
48+
self::markTestSkipped($e->getMessage());
49+
}
50+
}
51+
4352
public function testFromInvalidDsn()
4453
{
4554
$this->expectException(\InvalidArgumentException::class);
@@ -143,6 +152,14 @@ public function testDeprecationIfInvalidOptionIsPassedWithDsn()
143152
Connection::fromDsn('redis://localhost/queue?foo=bar');
144153
}
145154

155+
public function testRedisClusterInstanceIsSupported()
156+
{
157+
$this->skipIfRedisClusterUnavailable();
158+
159+
$redis = new \RedisCluster(null, explode(' ', getenv('REDIS_CLUSTER_HOSTS')));
160+
$this->assertInstanceOf(Connection::class, new Connection([], [], [], $redis));
161+
}
162+
146163
public function testKeepGettingPendingMessages()
147164
{
148165
$redis = $this->createMock(\Redis::class);

‎src/Symfony/Component/Messenger/Bridge/Redis/Transport/Connection.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Messenger/Bridge/Redis/Transport/Connection.php
+10-4Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ class Connection
5656
private $deleteAfterReject;
5757
private $couldHavePendingMessages = true;
5858

59-
public function __construct(array $configuration, array $connectionCredentials = [], array $redisOptions = [], \Redis $redis = null)
59+
/**
60+
* @param \Redis|\RedisCluster|null $redis
61+
*/
62+
public function __construct(array $configuration, array $connectionCredentials = [], array $redisOptions = [], $redis = null)
6063
{
6164
if (version_compare(phpversion('redis'), '4.3.0', '<')) {
6265
throw new LogicException('The redis transport requires php-redis 4.3.0 or higher.');
@@ -72,14 +75,17 @@ public function __construct(array $configuration, array $connectionCredentials =
7275
}
7376

7477
$initializer = static function ($redis) use ($host, $port, $auth, $serializer, $dbIndex) {
75-
$redis->connect($host, $port);
78+
if ($redis instanceof \Redis) {
79+
$redis->connect($host, $port);
80+
}
81+
7682
$redis->setOption(\Redis::OPT_SERIALIZER, $serializer);
7783

78-
if (null !== $auth && !$redis->auth($auth)) {
84+
if (null !== $auth && $redis instanceof \Redis && !$redis->auth($auth)) {
7985
throw new InvalidArgumentException('Redis connection failed: '.$redis->getLastError());
8086
}
8187

82-
if ($dbIndex && !$redis->select($dbIndex)) {
88+
if ($dbIndex && $redis instanceof \Redis && !$redis->select($dbIndex)) {
8389
throw new InvalidArgumentException('Redis connection failed: '.$redis->getLastError());
8490
}
8591

‎src/Symfony/Component/Messenger/Bridge/Redis/Transport/RedisProxy.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Messenger/Bridge/Redis/Transport/RedisProxy.php
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ class RedisProxy
2525
private $initializer;
2626
private $ready = false;
2727

28-
public function __construct(\Redis $redis, \Closure $initializer)
28+
/**
29+
* @param \Redis|\RedisCluster $redis
30+
*/
31+
public function __construct($redis, \Closure $initializer)
2932
{
3033
$this->redis = $redis;
3134
$this->initializer = $initializer;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.