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

Skip to content

Commit 6f4e0a4

Browse files
author
Frederik Schwan
committed
fix redis messenger scheme comparison
Commit 3380518 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
1 parent a314b65 commit 6f4e0a4

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

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

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,48 @@ public function testSupportsOnlyRedisTransports()
2828

2929
$this->assertTrue($factory->supports('redis://localhost', []));
3030
$this->assertTrue($factory->supports('rediss://localhost', []));
31+
$this->assertTrue($factory->supports('redis:?host[host1:5000]&host[host2:5000]&host[host3:5000]&sentinel_master=test&dbindex=0', []));
3132
$this->assertFalse($factory->supports('sqs://localhost', []));
3233
$this->assertFalse($factory->supports('invalid-dsn', []));
3334
}
3435

3536
/**
3637
* @group integration
38+
*
39+
* @dataProvider createTransportProvider
3740
*/
38-
public function testCreateTransport()
41+
public function testCreateTransport(string $dsn, array $options = [])
3942
{
4043
$this->skipIfRedisUnavailable();
4144

4245
$factory = new RedisTransportFactory();
4346
$serializer = $this->createMock(SerializerInterface::class);
44-
$expectedTransport = new RedisTransport(Connection::fromDsn('redis://'.getenv('REDIS_HOST'), ['stream' => 'bar', 'delete_after_ack' => true]), $serializer);
4547

46-
$this->assertEquals($expectedTransport, $factory->createTransport('redis://'.getenv('REDIS_HOST'), ['stream' => 'bar', 'delete_after_ack' => true], $serializer));
48+
$this->assertEquals(
49+
new RedisTransport(Connection::fromDsn($dsn, $options), $serializer),
50+
$factory->createTransport($dsn, $options, $serializer)
51+
);
52+
}
53+
54+
/**
55+
* @return iterable<array{0: string, 1: array}>
56+
*/
57+
public static function createTransportProvider(): iterable
58+
{
59+
yield 'scheme "redis" without options' => [
60+
'redis://'.getenv('REDIS_HOST'),
61+
[],
62+
];
63+
64+
yield 'scheme "redis" with options' => [
65+
'redis://'.getenv('REDIS_HOST'),
66+
['stream' => 'bar', 'delete_after_ack' => true],
67+
];
68+
69+
yield 'redis_sentinel' => [
70+
'redis:?host['.str_replace(' ', ']&host[', getenv('REDIS_SENTINEL_HOSTS')).']',
71+
['sentinel_master' => getenv('REDIS_SENTINEL_SERVICE')],
72+
];
4773
}
4874

4975
private function skipIfRedisUnavailable()

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@ public function createTransport(#[\SensitiveParameter] string $dsn, array $optio
3232

3333
public function supports(#[\SensitiveParameter] string $dsn, array $options): bool
3434
{
35-
return str_starts_with($dsn, 'redis://') || str_starts_with($dsn, 'rediss://');
35+
return str_starts_with($dsn, 'redis:') || str_starts_with($dsn, 'rediss:');
3636
}
3737
}

0 commit comments

Comments
 (0)