Skip to content

Commit

Permalink
feature symfony#52893 [Cache][Messenger]  make both options redis_sen…
Browse files Browse the repository at this point in the history
…tinel and sentinel_master available everywhere (xabbuh)

This PR was merged into the 7.1 branch.

Discussion
----------

[Cache][Messenger]  make both options redis_sentinel and sentinel_master available everywhere

| Q             | A
| ------------- | ---
| Branch?       | 7.1
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Issues        | Fix symfony#52671
| License       | MIT

Commits
-------

7c1bfcf make both options redis_sentinel and sentinel_master available everywhere
  • Loading branch information
fabpot committed Dec 8, 2023
2 parents 229cbf2 + 7c1bfcf commit 48951a0
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/Symfony/Component/Cache/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

7.1
---

* Add option `sentinel_master` as an alias for `redis_sentinel`

7.0
---

Expand Down
6 changes: 6 additions & 0 deletions src/Symfony/Component/Cache/Traits/RedisTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,12 @@ public static function createConnection(#[\SensitiveParameter] string $dsn, arra

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

if (isset($params['redis_sentinel']) && isset($params['sentinel_master'])) {
throw new InvalidArgumentException('Cannot use both "redis_sentinel" and "sentinel_master" at the same time.');
}

$params['redis_sentinel'] ??= $params['sentinel_master'] ?? null;

if (isset($params['redis_sentinel']) && !class_exists(\Predis\Client::class) && !class_exists(\RedisSentinel::class) && !class_exists(Sentinel::class)) {
throw new CacheException('Redis Sentinel support requires one of: "predis/predis", "ext-redis >= 5.2", "ext-relay".');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,10 @@ public function testConnectionClaimAndRedeliver()
$connection->ack($message['id']);
}

public function testSentinel()
/**
* @dataProvider
*/
public function testSentinel(string $sentinelOptionName)
{
if (!$hosts = getenv('REDIS_SENTINEL_HOSTS')) {
$this->markTestSkipped('REDIS_SENTINEL_HOSTS env var is not defined.');
Expand All @@ -234,7 +237,7 @@ public function testSentinel()

$connection = Connection::fromDsn($dsn,
['delete_after_ack' => true,
'sentinel_master' => getenv('MESSENGER_REDIS_SENTINEL_MASTER') ?: null,
$sentinelOptionName => getenv('MESSENGER_REDIS_SENTINEL_MASTER') ?: null,
], $this->redis);

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

public function sentinelOptionNames(): iterable
{
yield 'redis_sentinel';
yield 'sentinel_master';
}

public function testLazySentinel()
{
$connection = Connection::fromDsn(getenv('MESSENGER_REDIS_DSN'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,12 @@ public function __construct(array $options, \Redis|Relay|\RedisCluster $redis =
$host = $options['host'];
$port = $options['port'];
$auth = $options['auth'];
$sentinelMaster = $options['sentinel_master'];

if (isset($options['redis_sentinel']) && isset($options['sentinel_master'])) {
throw new InvalidArgumentException('Cannot use both "redis_sentinel" and "sentinel_master" at the same time.');
}

$sentinelMaster = $options['sentinel_master'] ?? $options['redis_sentinel'] ?? null;

if (null !== $sentinelMaster && !class_exists(\RedisSentinel::class) && !class_exists(Sentinel::class)) {
throw new InvalidArgumentException('Redis Sentinel support requires ext-redis>=5.2, or ext-relay.');
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/Messenger/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ CHANGELOG
7.1
---

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

7.0
Expand Down

0 comments on commit 48951a0

Please sign in to comment.