Skip to content

Commit 7c1bfcf

Browse files
committed
make both options redis_sentinel and sentinel_master available everywhere
1 parent dc330b0 commit 7c1bfcf

File tree

5 files changed

+29
-3
lines changed

5 files changed

+29
-3
lines changed

src/Symfony/Component/Cache/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
7.1
5+
---
6+
7+
* Add option `sentinel_master` as an alias for `redis_sentinel`
8+
49
7.0
510
---
611

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,12 @@ public static function createConnection(#[\SensitiveParameter] string $dsn, arra
169169

170170
$params += $query + $options + self::$defaultConnectionOptions;
171171

172+
if (isset($params['redis_sentinel']) && isset($params['sentinel_master'])) {
173+
throw new InvalidArgumentException('Cannot use both "redis_sentinel" and "sentinel_master" at the same time.');
174+
}
175+
176+
$params['redis_sentinel'] ??= $params['sentinel_master'] ?? null;
177+
172178
if (isset($params['redis_sentinel']) && !class_exists(\Predis\Client::class) && !class_exists(\RedisSentinel::class) && !class_exists(Sentinel::class)) {
173179
throw new CacheException('Redis Sentinel support requires one of: "predis/predis", "ext-redis >= 5.2", "ext-relay".');
174180
}

src/Symfony/Component/Messenger/Bridge/Redis/Tests/Transport/RedisExtIntegrationTest.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,10 @@ public function testConnectionClaimAndRedeliver()
220220
$connection->ack($message['id']);
221221
}
222222

223-
public function testSentinel()
223+
/**
224+
* @dataProvider
225+
*/
226+
public function testSentinel(string $sentinelOptionName)
224227
{
225228
if (!$hosts = getenv('REDIS_SENTINEL_HOSTS')) {
226229
$this->markTestSkipped('REDIS_SENTINEL_HOSTS env var is not defined.');
@@ -234,7 +237,7 @@ public function testSentinel()
234237

235238
$connection = Connection::fromDsn($dsn,
236239
['delete_after_ack' => true,
237-
'sentinel_master' => getenv('MESSENGER_REDIS_SENTINEL_MASTER') ?: null,
240+
$sentinelOptionName => getenv('MESSENGER_REDIS_SENTINEL_MASTER') ?: null,
238241
], $this->redis);
239242

240243
$connection->add('1', []);
@@ -249,6 +252,12 @@ public function testSentinel()
249252
$connection->cleanup();
250253
}
251254

255+
public function sentinelOptionNames(): iterable
256+
{
257+
yield 'redis_sentinel';
258+
yield 'sentinel_master';
259+
}
260+
252261
public function testLazySentinel()
253262
{
254263
$connection = Connection::fromDsn(getenv('MESSENGER_REDIS_DSN'),

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,12 @@ public function __construct(array $options, \Redis|Relay|\RedisCluster $redis =
7878
$host = $options['host'];
7979
$port = $options['port'];
8080
$auth = $options['auth'];
81-
$sentinelMaster = $options['sentinel_master'];
81+
82+
if (isset($options['redis_sentinel']) && isset($options['sentinel_master'])) {
83+
throw new InvalidArgumentException('Cannot use both "redis_sentinel" and "sentinel_master" at the same time.');
84+
}
85+
86+
$sentinelMaster = $options['sentinel_master'] ?? $options['redis_sentinel'] ?? null;
8287

8388
if (null !== $sentinelMaster && !class_exists(\RedisSentinel::class) && !class_exists(Sentinel::class)) {
8489
throw new InvalidArgumentException('Redis Sentinel support requires ext-redis>=5.2, or ext-relay.');

src/Symfony/Component/Messenger/CHANGELOG.md

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

7+
* Add option `redis_sentinel` as an alias for `sentinel_master`
78
* Add `--all` option to the `messenger:consume` command
89

910
7.0

0 commit comments

Comments
 (0)