From 6f4e0a401bcd28bfe9d24741b6ea7b0b1edec296 Mon Sep 17 00:00:00 2001 From: Frederik Schwan Date: Thu, 7 Dec 2023 17:08:30 +0100 Subject: [PATCH] fix redis messenger scheme comparison Commit 3380518b88f8303ad9428f26c103e6b3b64a9fc5 introduced a new Redis Sentinel DSN for the redis messenger transport which uses a scheme syntax like `redis:?host[rs:1234]&host[rs2:1234]`. Though, the coresponding factory only supports schemes which start with `redis://` or `rediss://` which renders the redis sentinel features for the messenger unusable. This commit fixes the supported schemes by removing the `//` portion of them. fixes #52899 --- .../Transport/RedisTransportFactoryTest.php | 32 +++++++++++++++++-- .../Redis/Transport/RedisTransportFactory.php | 2 +- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/Messenger/Bridge/Redis/Tests/Transport/RedisTransportFactoryTest.php b/src/Symfony/Component/Messenger/Bridge/Redis/Tests/Transport/RedisTransportFactoryTest.php index 5c7caff199ea0..93e5e890fd471 100644 --- a/src/Symfony/Component/Messenger/Bridge/Redis/Tests/Transport/RedisTransportFactoryTest.php +++ b/src/Symfony/Component/Messenger/Bridge/Redis/Tests/Transport/RedisTransportFactoryTest.php @@ -28,22 +28,48 @@ public function testSupportsOnlyRedisTransports() $this->assertTrue($factory->supports('redis://localhost', [])); $this->assertTrue($factory->supports('rediss://localhost', [])); + $this->assertTrue($factory->supports('redis:?host[host1:5000]&host[host2:5000]&host[host3:5000]&sentinel_master=test&dbindex=0', [])); $this->assertFalse($factory->supports('sqs://localhost', [])); $this->assertFalse($factory->supports('invalid-dsn', [])); } /** * @group integration + * + * @dataProvider createTransportProvider */ - public function testCreateTransport() + public function testCreateTransport(string $dsn, array $options = []) { $this->skipIfRedisUnavailable(); $factory = new RedisTransportFactory(); $serializer = $this->createMock(SerializerInterface::class); - $expectedTransport = new RedisTransport(Connection::fromDsn('redis://'.getenv('REDIS_HOST'), ['stream' => 'bar', 'delete_after_ack' => true]), $serializer); - $this->assertEquals($expectedTransport, $factory->createTransport('redis://'.getenv('REDIS_HOST'), ['stream' => 'bar', 'delete_after_ack' => true], $serializer)); + $this->assertEquals( + new RedisTransport(Connection::fromDsn($dsn, $options), $serializer), + $factory->createTransport($dsn, $options, $serializer) + ); + } + + /** + * @return iterable + */ + public static function createTransportProvider(): iterable + { + yield 'scheme "redis" without options' => [ + 'redis://'.getenv('REDIS_HOST'), + [], + ]; + + yield 'scheme "redis" with options' => [ + 'redis://'.getenv('REDIS_HOST'), + ['stream' => 'bar', 'delete_after_ack' => true], + ]; + + yield 'redis_sentinel' => [ + 'redis:?host['.str_replace(' ', ']&host[', getenv('REDIS_SENTINEL_HOSTS')).']', + ['sentinel_master' => getenv('REDIS_SENTINEL_SERVICE')], + ]; } private function skipIfRedisUnavailable() diff --git a/src/Symfony/Component/Messenger/Bridge/Redis/Transport/RedisTransportFactory.php b/src/Symfony/Component/Messenger/Bridge/Redis/Transport/RedisTransportFactory.php index f7e9956809ba2..89ebf6ee119be 100644 --- a/src/Symfony/Component/Messenger/Bridge/Redis/Transport/RedisTransportFactory.php +++ b/src/Symfony/Component/Messenger/Bridge/Redis/Transport/RedisTransportFactory.php @@ -32,6 +32,6 @@ public function createTransport(#[\SensitiveParameter] string $dsn, array $optio public function supports(#[\SensitiveParameter] string $dsn, array $options): bool { - return str_starts_with($dsn, 'redis://') || str_starts_with($dsn, 'rediss://'); + return str_starts_with($dsn, 'redis:') || str_starts_with($dsn, 'rediss:'); } } 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