8000 [Semaphore] allow redis cluster/sentinel dsn · symfony/symfony@9c0213b · GitHub
[go: up one dir, main page]

Skip to content

Commit 9c0213b

Browse files
committed
[Semaphore] allow redis cluster/sentinel dsn
1 parent 6caa25d commit 9c0213b

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