From 6a260724660363fc5c64b464cee837b7d8424565 Mon Sep 17 00:00:00 2001 From: Alexey Vlasov <50667072+adideas@users.noreply.github.com> Date: Wed, 8 May 2024 15:21:26 +0300 Subject: [PATCH] Added the ability to force use RedisCluster in Messenger Previously, an array had to be specified to support a cluster. But the nodes can change. Instead of "redis://host-0,redis://host-1" we specify "redis://server?redis_cluster=true" --- .../Component/Messenger/Bridge/Redis/Transport/Connection.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Messenger/Bridge/Redis/Transport/Connection.php b/src/Symfony/Component/Messenger/Bridge/Redis/Transport/Connection.php index 7f52bdaf0f67..e0db406a7ee7 100644 --- a/src/Symfony/Component/Messenger/Bridge/Redis/Transport/Connection.php +++ b/src/Symfony/Component/Messenger/Bridge/Redis/Transport/Connection.php @@ -53,6 +53,7 @@ class Connection 'retry_interval' => 0, // Int, value in milliseconds (optional, default is 0) 'persistent_id' => null, // String, persistent connection id (optional, default is NULL meaning not persistent) 'ssl' => null, // see https://php.net/context.ssl + 'redis_cluster' => false, // force use of cluster ]; private \Redis|Relay|\RedisCluster|\Closure $redis; @@ -110,7 +111,7 @@ public function __construct(array $options, \Redis|Relay|\RedisCluster|null $red } } - if ((\is_array($host) && null === $sentinelMaster) || $redis instanceof \RedisCluster) { + if ((\is_array($host) && null === $sentinelMaster) || $redis instanceof \RedisCluster || $options['redis_cluster']) { $hosts = \is_string($host) ? [$host.':'.$port] : $host; // Always ensure we have an array $this->redis = static fn () => self::initializeRedisCluster($redis, $hosts, $auth, $options); } else {