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 https://github.com/symfony/symfony/pull/39599) and deprecates the use of `tls` parameter introduced in https://github.com/symfony/symfony/pull/35503 so it can be standardized to single format.

Commits
-------

28e7b74b47 [Messenger] Add `rediss://` DSN scheme support for TLS to Redis transport
This commit is contained in:
Nicolas Grekas 2021-02-26 01:02:05 +01:00
commit 59fbe57ed1
6 changed files with 31 additions and 4 deletions

View File

@ -50,6 +50,7 @@ Messenger
---------
* Deprecated the `prefetch_count` parameter in the AMQP bridge, it has no effect and will be removed in Symfony 6.0
* Deprecated the use of TLS option for Redis Bridge, use `rediss://127.0.0.1` instead of `redis://127.0.0.1?tls=1`
Notifier
--------

View File

@ -122,6 +122,7 @@ Messenger
* The signature of method `RetryStrategyInterface::isRetryable()` has been updated to `RetryStrategyInterface::isRetryable(Envelope $message, \Throwable $throwable = null)`.
* The signature of method `RetryStrategyInterface::getWaitingTime()` has been updated to `RetryStrategyInterface::getWaitingTime(Envelope $message, \Throwable $throwable = null)`.
* Removed the `prefetch_count` parameter in the AMQP bridge.
* Removed the use of TLS option for Redis Bridge, use `rediss://127.0.0.1` instead of `redis://127.0.0.1?tls=1`
Mime
----

View File

@ -1,6 +1,12 @@
CHANGELOG
=========
5.3
---
* Add `rediss://` DSN scheme support for TLS protocol
* Deprecate TLS option, use `rediss://127.0.0.1` instead of `redis://127.0.0.1?tls=1`
5.2.0
-----

View File

@ -86,6 +86,9 @@ class ConnectionTest extends TestCase
);
}
/**
* @group legacy
*/
public function testFromDsnWithTls()
{
$redis = $this->createMock(\Redis::class);
@ -97,6 +100,9 @@ class ConnectionTest extends TestCase
Connection::fromDsn('redis://127.0.0.1?tls=1', [], $redis);
}
/**
* @group legacy
*/
public function testFromDsnWithTlsOption()
{
$redis = $this->createMock(\Redis::class);
@ -108,6 +114,17 @@ class ConnectionTest extends TestCase
Connection::fromDsn('redis://127.0.0.1', ['tls' => true], $redis);
}
public function testFromDsnWithRedissScheme()
{
$redis = $this->createMock(\Redis::class);
$redis->expects($this->once())
->method('connect')
->with('tls://127.0.0.1', 6379)
->willReturn(null);
Connection::fromDsn('rediss://127.0.0.1', [], $redis);
}
public function testFromDsnWithQueryOptions()
{
$this->assertEquals(

View File

@ -119,9 +119,10 @@ class Connection
public static function fromDsn(string $dsn, array $redisOptions = [], \Redis $redis = null): self
{
$url = $dsn;
$scheme = 0 === strpos($dsn, 'rediss:') ? 'rediss' : 'redis';
if (preg_match('#^redis:///([^:@])+$#', $dsn)) {
$url = str_replace('redis:', 'file:', $dsn);
if (preg_match('#^'.$scheme.':///([^:@])+$#', $dsn)) {
$url = str_replace($scheme.':', 'file:', $dsn);
}
if (false === $parsedUrl = parse_url($url)) {
@ -164,8 +165,9 @@ class Connection
unset($redisOptions['dbindex']);
}
$tls = false;
$tls = 'rediss' === $scheme;
if (\array_key_exists('tls', $redisOptions)) {
trigger_deprecation('symfony/redis-messenger', '5.3', 'Providing "tls" parameter is deprecated, use "rediss://" DSN scheme instead');
$tls = filter_var($redisOptions['tls'], \FILTER_VALIDATE_BOOLEAN);
unset($redisOptions['tls']);
}

View File

@ -43,7 +43,7 @@ class TransportFactory implements TransportFactoryInterface
$packageSuggestion = ' Run "composer require symfony/amqp-messenger" to install AMQP transport.';
} elseif (0 === strpos($dsn, 'doctrine://')) {
$packageSuggestion = ' Run "composer require symfony/doctrine-messenger" to install Doctrine transport.';
} elseif (0 === strpos($dsn, 'redis://')) {
} elseif (0 === strpos($dsn, 'redis://') || 0 === strpos($dsn, 'rediss://')) {
$packageSuggestion = ' Run "composer require symfony/redis-messenger" to install Redis transport.';
} elseif (0 === strpos($dsn, 'sqs://') || preg_match('#^https://sqs\.[\w\-]+\.amazonaws\.com/.+#', $dsn)) {
$packageSuggestion = ' Run "composer require symfony/amazon-sqs-messenger" to install Amazon SQS transport.';