8000 bug #59803 [Semaphore] allow redis cluster/sentinel dsn (smoench) · symfony/symfony@f48cf1b · GitHub
[go: up one dir, main page]

Skip to content

Commit f48cf1b

Browse files
bug #59803 [Semaphore] allow redis cluster/sentinel dsn (smoench)
This PR was merged into the 6.4 branch. Discussion ---------- [Semaphore] allow redis cluster/sentinel dsn | 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 | - | License | MIT This PR allows to use redis cluster/sentinel DSN for configuration. It syncs the same behaviour from [Lock Component StoreFactory](https://github.com/symfony/symfony/blob/6.4/src/Symfony/Component/Lock/Store/StoreFactory.php#L63). Commits ------- 9c0213b [Semaphore] allow redis cluster/sentinel dsn
2 parents 132c2a7 + 9c0213b commit f48cf1b

File tree

2 files changed

+18
-35
lines changed

2 files changed

+18
-35
lines changed

src/Symfony/Component/Semaphore/Store/StoreFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ public static function createStore(#[\SensitiveParameter] object|string $connect
3535

3636
case !\is_string($connection):
3737
throw new InvalidArgumentException(sprintf('Unsupported Connection: "%s".', $connection::class));
38-
case str_starts_with($connection, 'redis://'):
39-
case str_starts_with($connection, 'rediss://'):
38+
case str_starts_with($connection, 'redis:'):
39+
case str_starts_with($connection, 'rediss:'):
4040
if (!class_exists(AbstractAdapter::class)) {
4141
throw new InvalidArgumentException('Unsupported Redis DSN. Try running "composer require symfony/cache".');
4242
}

src/Symfony/Component/Semaphore/Tests/Store/StoreFactoryTest.php

Lines changed: 16 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,54 +12,37 @@
1212
namespace Symfony\Component\Semaphore\Tests\Store;
1313

1414
use PHPUnit\Framework\TestCase;
15-
use Symfony\Component\Cache\Traits\RedisProxy;
1615
use Symfony\Component\Semaphore\Store\RedisStore;
1716
use Symfony\Component\Semaphore\Store\StoreFactory;
1817

1918
/**
2019
* @author Jérémy Derussé <jeremy@derusse.com>
21-
*
22-
* @requires extension redis
2320
*/
2421
class StoreFactoryTest extends TestCase
2522
{
26-
public function testCreateRedisStore()
23+
/**
24+
* @dataProvider validConnections
25+
*/
26+
public function testCreateStore($connection, string $expectedStoreClass)
2727
{
28-
$store = StoreFactory::createStore($this->createMock(\Redis::class));
28+
$store = StoreFactory::createStore($connection);
2929

30-
$this->assertInstanceOf(RedisStore::class, $store);
30+
$this->assertInstanceOf($expectedStoreClass, $store);
3131
}
3232

33-
public function testCreateRedisProxyStore()
33+
public static function validConnections(): \Generator
3434
{
35-
if (!class_exists(RedisProxy::class)) {
36-
$this->markTestSkipped();
37-
}
35+
yield [new \Predis\Client(), RedisStore::class];
3836

39-
$store = StoreFactory::createStore($this->createMock(RedisProxy::class));
40-
41-
$this->assertInstanceOf(RedisStore::class, $store);
42-
}
43-
44-
public function testCreateRedisAsDsnStore()
45-
{
46-
if (!class_exists(RedisProxy::class)) {
47-
$this->markTestSkipped();
37+
if (class_exists(\Redis::class)) {
38+
yield [new \Redis(), RedisStore::class];
4839
}
49-
50-
$store = StoreFactory::createStore('redis://localhost');
51-
52-
$this->assertInstanceOf(RedisStore::class, $store);
53-
}
54-
55-
public function testCreatePredisStore()
56-
{
57-
if (!class_exists(\Predis\Client::class)) {
58-
$this->markTestSkipped();
40+
if (class_exists(\Redis::class) && class_exists(AbstractAdapter::class)) {
41+
yield ['redis://localhost', RedisStore::class];
42+
yield ['redis://localhost?lazy=1', RedisStore::class];
43+
yield ['redis://localhost?redis_cluster=1', RedisStore::class];
44+
yield ['redis://localhost?redis_cluster=1&lazy=1', RedisStore::class];
45+
yield ['redis:?host[localhost]&host[localhost:6379]&redis_cluster=1', RedisStore::class];
5946
}
60-
61-
$store = StoreFactory::createStore(new \Predis\Client());
62-
63-
$this->assertInstanceOf(RedisStore::class, $store);
6447
}
6548
}

0 commit comments

Comments
 (0)
0