[Lock] Fix StoreFactory to accept same DSN syntax as AbstractAdapter
This commit is contained in:
parent
44dd80f3fd
commit
4ebbe3d86b
@ -66,13 +66,13 @@ class StoreFactory
|
||||
case 'semaphore' === $connection:
|
||||
return new SemaphoreStore();
|
||||
|
||||
case 0 === strpos($connection, 'redis://'):
|
||||
case 0 === strpos($connection, 'rediss://'):
|
||||
case 0 === strpos($connection, 'memcached://'):
|
||||
case 0 === strpos($connection, 'redis:'):
|
||||
case 0 === strpos($connection, 'rediss:'):
|
||||
case 0 === strpos($connection, 'memcached:'):
|
||||
if (!class_exists(AbstractAdapter::class)) {
|
||||
throw new InvalidArgumentException(sprintf('Unsupported DSN "%s". Try running "composer require symfony/cache".', $connection));
|
||||
}
|
||||
$storeClass = 0 === strpos($connection, 'memcached://') ? MemcachedStore::class : RedisStore::class;
|
||||
$storeClass = 0 === strpos($connection, 'memcached:') ? MemcachedStore::class : RedisStore::class;
|
||||
$connection = AbstractAdapter::createConnection($connection, ['lazy' => true]);
|
||||
|
||||
return new $storeClass($connection);
|
||||
|
@ -58,12 +58,14 @@ class StoreFactoryTest extends TestCase
|
||||
}
|
||||
if (class_exists(\Memcached::class) && class_exists(AbstractAdapter::class)) {
|
||||
yield ['memcached://server.com', MemcachedStore::class];
|
||||
yield ['memcached:?host[localhost]&host[localhost:12345]', MemcachedStore::class];
|
||||
}
|
||||
if (class_exists(\Redis::class) && class_exists(AbstractAdapter::class)) {
|
||||
if ((class_exists(\Redis::class) || class_exists(\Predis\Client::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];
|
||||
}
|
||||
if (class_exists(\PDO::class)) {
|
||||
yield ['sqlite:/tmp/sqlite.db', PdoStore::class];
|
||||
|
Reference in New Issue
Block a user