Skip to content

Commit

Permalink
[Lock] Fix StoreFactory to accept same DSN syntax as AbstractAdapter
Browse files Browse the repository at this point in the history
  • Loading branch information
Jontsa authored and fabpot committed Oct 3, 2020
1 parent 26ddd81 commit 4b86757
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 4 additions & 4 deletions Store/StoreFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ public static function createStore($connection)
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);
Expand Down
4 changes: 3 additions & 1 deletion Tests/Store/StoreFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,14 @@ public function validConnections()
}
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];
Expand Down

0 comments on commit 4b86757

Please sign in to comment.