Skip to content

Commit 592d0fd

Browse files
committed
[Messenger] Add TLS alternative to Redis transport's DSN with rediss:// scheme
1 parent f2b98b4 commit 592d0fd

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ CHANGELOG
77
* Added a `delete_after_reject` option to the DSN to allow control over message
88
deletion, similar to `delete_after_ack`.
99
* Added option `lazy` to delay connecting to Redis server until we first use it.
10+
* Added `rediss://` scheme support for TLS protocol in addition to the TLS option in the DNS.
11+
Example: `rediss://127.0.0.1` will behave like `redis://127.0.0.1?tls=1`
1012

1113
5.1.0
1214
-----

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,17 @@ public function testFromDsnWithTlsOption()
108108
Connection::fromDsn('redis://127.0.0.1', ['tls' => true], $redis);
109109
}
110110

111+
public function testFromDsnWithRedissScheme()
112+
{
113+
$redis = $this->createMock(\Redis::class);
114+
$redis->expects($this->once())
115+
->method('connect')
116+
->with('tls://127.0.0.1', 6379)
117+
->willReturn(null);
118+
119+
Connection::fromDsn('rediss://127.0.0.1', [], $redis);
120+
}
121+
111122
public function testFromDsnWithQueryOptions()
112123
{
113124
$this->assertEquals(

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,13 @@ public static function fromDsn(string $dsn, array $redisOptions = [], \Redis $re
120120
{
121121
$url = $dsn;
122122

123-
if (preg_match('#^redis:///([^:@])+$#', $dsn)) {
124-
$url = str_replace('redis:', 'file:', $dsn);
123+
$scheme = 'redis';
124+
if (0 === strpos($dsn, 'rediss:')) {
125+
$scheme = 'rediss';
126+
}
127+
128+
if (preg_match('#^'.$scheme.':///([^:@])+$#', $dsn)) {
129+
$url = str_replace($scheme.':', 'file:', $dsn);
125130
}
126131

127132
if (false === $parsedUrl = parse_url($url)) {
@@ -164,6 +169,9 @@ public static function fromDsn(string $dsn, array $redisOptions = [], \Redis $re
164169
}
165170

166171
$tls = false;
172+
if ('rediss' === $scheme) {
173+
$tls = true;
174+
}
167175
if (\array_key_exists('tls', $redisOptions)) {
168176
$tls = filter_var($redisOptions['tls'], \FILTER_VALIDATE_BOOLEAN);
169177
unset($redisOptions['tls']);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy