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

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[Semaphore] allow redis cluster/sentinel dsn
  • Loading branch information
smoench committed Feb 18, 2025
commit 9c0213b0d23688c74c09b2d5586fde96c12afa64
4 changes: 2 additions & 2 deletions src/Symfony/Component/Semaphore/Store/StoreFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public static function createStore(#[\SensitiveParameter] object|string $connect

case !\is_string($connection):
throw new InvalidArgumentException(sprintf('Unsupported Connection: "%s".', $connection::class));
case str_starts_with($connection, 'redis://'):
case str_starts_with($connection, 'rediss://'):
case str_starts_with($connection, 'redis:'):
case str_starts_with($connection, 'rediss:'):
if (!class_exists(AbstractAdapter::class)) {
throw new InvalidArgumentException('Unsupported Redis DSN. Try running "composer require symfony/cache".');
}
Expand Down
49 changes: 16 additions & 33 deletions src/Symfony/Component/Semaphore/Tests/Store/StoreFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,54 +12,37 @@
namespace Symfony\Component\Semaphore\Tests\Store;

use PHPUnit\Framework\TestCase;
use Symfony\Component\Cache\Traits\RedisProxy;
use Symfony\Component\Semaphore\Store\RedisStore;
use Symfony\Component\Semaphore\Store\StoreFactory;

/**
* @author Jérémy Derussé <[email protected]>
*
* @requires extension redis
*/
class StoreFactoryTest extends TestCase
{
public function testCreateRedisStore()
/**
* @dataProvider validConnections
*/
public function testCreateStore($connection, string $expectedStoreClass)
{
$store = StoreFactory::createStore($this->createMock(\Redis::class));
$store = StoreFactory::createStore($connection);

$this->assertInstanceOf(RedisStore::class, $store);
$this->assertInstanceOf($expectedStoreClass, $store);
}

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

$store = StoreFactory::createStore($this->createMock(RedisProxy::class));

$this->assertInstanceOf(RedisStore::class, $store);
}

public function testCreateRedisAsDsnStore()
{
if (!class_exists(RedisProxy::class)) {
$this->markTestSkipped();
if (class_exists(\Redis::class)) {
yield [new \Redis(), RedisStore::class];
}

$store = StoreFactory::createStore('redis://localhost');

$this->assertInstanceOf(RedisStore::class, $store);
}

public function testCreatePredisStore()
{
if (!class_exists(\Predis\Client::class)) {
$this->markTestSkipped();
if (class_exists(\Redis::class) && class_exists(AbstractAdapter::class)) {
yield ['redis://localhost', RedisStore::class];
yield ['redis://localhost?lazy=1', RedisStore::class];
yield ['redis://localhost?redis_cluster=1', RedisStore::class];
yield ['redis://localhost?redis_cluster=1&lazy=1', RedisStore::class];
yield ['redis:?host[localhost]&host[localhost:6379]&redis_cluster=1', RedisStore::class];
}

$store = StoreFactory::createStore(new \Predis\Client());

$this->assertInstanceOf(RedisStore::class, $store);
}
}
Loading