Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 09ec907

Browse files
Nyholmfabpot
authored andcommitted
[Messenger] Add TLS option to Redis transport's DSN
1 parent f0748f8 commit 09ec907

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ CHANGELOG
55
-----
66

77
* Introduced the Redis bridge.
8+
* Added TLS option in the DSN. Example: `redis://127.0.0.1?tls=1`

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
namespace Symfony\Component\Messenger\Bridge\Redis\Tests\Transport;
1313

1414
use PHPUnit\Framework\TestCase;
15-
use Symfony\Component\Messenger\Exception\TransportException;
1615
use Symfony\Component\Messenger\Bridge\Redis\Transport\Connection;
16+
use Symfony\Component\Messenger\Exception\TransportException;
1717

1818
/**
1919
* @requires extension redis >= 4.3.0
@@ -73,6 +73,28 @@ public function testFromDsnWithOptions()
7373
);
7474
}
7575

76+
public function testFromDsnWithTls()
77+
{
78+
$redis = $this->createMock(\Redis::class);
79+
$redis->expects($this->once())
80+
->method('connect')
81+
->with('tls://127.0.0.1', 6379)
82+
->willReturn(null);
83+
84+
Connection::fromDsn('redis://127.0.0.1?tls=1', [], $redis);
85+
}
86+
87+
public function testFromDsnWithTlsOption()
88+
{
89+
$redis = $this->createMock(\Redis::class);
90+
$redis->expects($this->once())
91+
->method('connect')
92+
->with('tls://127.0.0.1', 6379)
93+
->willReturn(null);
94+
95+
Connection::fromDsn('redis://127.0.0.1', ['tls' => true], $redis);
96+
}
97+
7698
public function testFromDsnWithQueryOptions()
7799
{
78100
$this->assertEquals(

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ public static function fromDsn(string $dsn, array $redisOptions = [], \Redis $re
104104
unset($redisOptions['dbindex']);
105105
}
106106

107+
$tls = false;
108+
if (\array_key_exists('tls', $redisOptions)) {
109+
$tls = filter_var($redisOptions['tls'], FILTER_VALIDATE_BOOLEAN);
110+
unset($redisOptions['tls']);
111+
}
112+
107113
$configuration = [
108114
'stream' => $redisOptions['stream'] ?? null,
109115
'group' => $redisOptions['group'] ?? null,
@@ -125,6 +131,9 @@ public static function fromDsn(string $dsn, array $redisOptions = [], \Redis $re
125131
$configuration['stream'] = $pathParts[1] ?? $configuration['stream'];
126132
$configuration['group'] = $pathParts[2] ?? $configuration['group'];
127133
$configuration['consumer'] = $pathParts[3] ?? $configuration['consumer'];
134+
if ($tls) {
135+
$connectionCredentials['host'] = 'tls://'.$connectionCredentials['host'];
136+
}
128137
} else {
129138
$connectionCredentials = [
130139
'host' => $parsedUrl['path'],

0 commit comments

Comments
 (0)