Skip to content

Commit

Permalink
bug #52930 [Messenger] Fix Redis messenger scheme comparison (freswa)
Browse files Browse the repository at this point in the history
This PR was merged into the 6.4 branch.

Discussion
----------

[Messenger] Fix Redis messenger scheme comparison

| Q             | A
| ------------- | ---
| Branch?       | 6.4
| Bug fix?      | yes
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Issues        | Fix #52899 <!-- prefix each issue number with "Fix #", no need to create an issue if none exists, explain below instead -->
| License       | MIT

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

Commits
-------

6f4e0a4 fix redis messenger scheme comparison
  • Loading branch information
nicolas-grekas committed Jan 2, 2024
2 parents a84d42b + 6f4e0a4 commit 712ccf5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
Expand Up @@ -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<array{0: string, 1: array}>
*/
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()
Expand Down
Expand Up @@ -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:');
}
}

0 comments on commit 712ccf5

Please sign in to comment.