Skip to content

Commit e2c8bdd

Browse files
njutn95nicolas-grekas
authored andcommitted
[Messenger] Add rediss:// DSN scheme support for TLS to Redis transport
1 parent 7e68914 commit e2c8bdd

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

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

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(

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
}

0 commit comments

Comments
 (0)