8000 feature #39607 [Messenger] Add `rediss://` DSN scheme support for TLS… · symfony/symfony@59fbe57 · GitHub
[go: up one dir, main page]

Skip to content

Commit 59fbe57

Browse files
feature #39607 [Messenger] Add rediss:// DSN scheme support for TLS to Redis transport (njutn95)
This PR was squashed before being merged into the 5.3-dev branch. Discussion ---------- [Messenger] Add `rediss://` DSN scheme support for TLS to Redis transport | Q | A | ------------- | --- | Branch? | 5.x | Bug fix? | no | New feature? | no | Deprecations? | yes | Tickets | | License | MIT | Doc PR | This adds a support for `rediss://` DSN (as discussed in #39599) and deprecates the use of `tls` parameter introduced in #35503 so it can be standardized to single format. Commits ------- 28e7b74 [Messenger] Add `rediss://` DSN scheme support for TLS to Redis transport
2 parents 008f280 + 28e7b74 commit 59fbe57

File tree

6 files changed

+31
-4
lines changed

6 files changed

+31
-4
lines changed

UPGRADE-5.3.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ Messenger
5050
---------
5151

5252
* Deprecated the `prefetch_count` parameter in the AMQP bridge, it has no effect and will be removed in Symfony 6.0
53+
* Deprecated the use of TLS option for Redis Bridge, use `rediss://127.0.0.1` instead of `redis://127.0.0.1?tls=1`
5354

5455
Notifier
5556
--------

UPGRADE-6.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ Messenger
122122
* The signature of method `RetryStrategyInterface::isRetryable()` has been updated to `RetryStrategyInterface::isRetryable(Envelope $message, \Throwable $throwable = null)`.
123123
* The signature of method `RetryStrategyInterface::getWaitingTime()` has been updated to `RetryStrategyInterface::getWaitingTime(Envelope $message, \Throwable $throwable = null)`.
124124
* Removed the `prefetch_count` parameter in the AMQP bridge.
125+
* Removed the use of TLS option for Redis Bridge, use `rediss://127.0.0.1` instead of `redis://127.0.0.1?tls=1`
125126

126127
Mime
127128
----

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

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

4+
5.3
5+
---
6+
7+
* Add `rediss://` DSN scheme support for TLS protocol
8+
* Deprecate TLS option, use `rediss://127.0.0.1` instead of `redis://127.0.0.1?tls=1`
9+
410
5.2.0
511
-----
612

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ public function testFromDsnWithOptionsAndTrailingSlash()
8686
);
8787
}
8888

89+
/**
90+
* @group legacy
91+
*/
8992
public function testFromDsnWithTls()
9093
{
9194
$redis = $this->createMock(\Redis::class);
@@ -97,6 +100,9 @@ public function testFromDsnWithTls()
97100
Connection::fromDsn('redis://127.0.0.1?tls=1', [], $redis);
98101
}
99102

103+
/**
104+
* @group legacy
105+
*/
100106
public function testFromDsnWithTlsOption()
101107
{
102108
$redis = $this->createMock(\Redis::class);
@@ -108,6 +114,17 @@ public function testFromDsnWithTlsOption()
108114
Connection::fromDsn('redis://127.0.0.1', ['tls' => true], $redis);
109115
}
110116

117+
public function testFromDsnWithRedissScheme()
118+
{
119+
$redis = $this->createMock(\Redis::class);
120+
$redis->expects($this->once())
121+
->method('connect')
122+
->with('tls://127.0.0.1', 6379)
123+
->willReturn(null);
124+
125+
Connection::fromDsn('rediss://127.0.0.1', [], $redis);
126+
}
127+
111128
public function testFromDsnWithQueryOptions()
112129
{
113130
$this->assertEquals(

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,10 @@ public function __construct(array $configuration, array $connectionCredentials =
119119
public static function fromDsn(string $dsn, array $redisOptions = [], \Redis $redis = null): self
120120
{
121121
$url = $dsn;
122+
$scheme = 0 === strpos($dsn, 'rediss:') ? 'rediss' : 'redis';
122123

123-
if (preg_match('#^redis:///([^:@])+$#', $dsn)) {
124-
$url = str_replace('redis:', 'file:', $dsn);
124+
if (preg_match('#^'.$scheme.':///([^:@])+$#', $dsn)) {
125+
$url = str_replace($scheme.':', 'file:', $dsn);
125126
}
126127

127128
if (false === $parsedUrl = parse_url($url)) {
@@ -164,8 +165,9 @@ public static function fromDsn(string $dsn, array $redisOptions = [], \Redis $re
164165
unset($redisOptions['dbindex']);
165166
}
166167

167-
$tls = false;
168+
$tls = 'rediss' === $scheme;
168169
if (\array_key_exists('tls', $redisOptions)) {
170+
trigger_deprecation('symfony/redis-messenger', '5.3', 'Providing "tls" parameter is deprecated, use "rediss://" DSN scheme instead');
169171
$tls = filter_var($redisOptions['tls'], \FILTER_VALIDATE_BOOLEAN);
170172
unset($redisOptions['tls']);
171173
}

src/Symfony/Component/Messenger/Transport/TransportFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function createTransport(string $dsn, array $options, SerializerInterface
4343
$packageSuggestion = ' Run "composer require symfony/amqp-messenger" to install AMQP transport.';
4444
} elseif (0 === strpos($dsn, 'doctrine://')) {
4545
$packageSuggestion = ' Run "composer require symfony/doctrine-messenger" to install Doctrine transport.';
46-
} elseif (0 === strpos($dsn, 'redis://')) {
46+
} elseif (0 === strpos($dsn, 'redis://') || 0 === strpos($dsn, 'rediss://')) {
4747
$packageSuggestion = ' Run "composer require symfony/redis-messenger" to install Redis transport.';
4848
} elseif (0 === strpos($dsn, 'sqs://') || preg_match('#^https://sqs\.[\w\-]+\.amazonaws\.com/.+#', $dsn)) {
4949
$packageSuggestion = ' Run "composer require symfony/amazon-sqs-messenger" to install Amazon SQS transport.';

0 commit comments

Comments
 (0)
0