Skip to content

Commit 4a501d4

Browse files
committed
bug #36291 [Lock] Fix StoreFactory to accept same DSN syntax as AbstractAdapter (Jontsa)
This PR was squashed before being merged into the 4.4 branch. Discussion ---------- [Lock] Fix StoreFactory to accept same DSN syntax as AbstractAdapter | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #35350 | License | MIT | Doc PR | Updates `Symfony\Component\Lock\Store\StoreFactory` to accept same DSN syntax as `Symfony\Component\Cache\Adapter\AbstractAdapter` which is used to create Redis class instance. Commits ------- 4ebbe3d86b [Lock] Fix StoreFactory to accept same DSN syntax as AbstractAdapter
2 parents 271201f + 4b86757 commit 4a501d4

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

Store/StoreFactory.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,13 @@ public static function createStore($connection)
6666
case 'semaphore' === $connection:
6767
return new SemaphoreStore();
6868

69-
case 0 === strpos($connection, 'redis://'):
70-
case 0 === strpos($connection, 'rediss://'):
71-
case 0 === strpos($connection, 'memcached://'):
69+
case 0 === strpos($connection, 'redis:'):
70+
case 0 === strpos($connection, 'rediss:'):
71+
case 0 === strpos($connection, 'memcached:'):
7272
if (!class_exists(AbstractAdapter::class)) {
7373
throw new InvalidArgumentException(sprintf('Unsupported DSN "%s". Try running "composer require symfony/cache".', $connection));
7474
}
75-
$storeClass = 0 === strpos($connection, 'memcached://') ? MemcachedStore::class : RedisStore::class;
75+
$storeClass = 0 === strpos($connection, 'memcached:') ? MemcachedStore::class : RedisStore::class;
7676
$connection = AbstractAdapter::createConnection($connection, ['lazy' => true]);
7777

7878
return new $storeClass($connection);

Tests/Store/StoreFactoryTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,14 @@ public function validConnections()
5858
}
5959
if (class_exists(\Memcached::class) && class_exists(AbstractAdapter::class)) {
6060
yield ['memcached://server.com', MemcachedStore::class];
61+
yield ['memcached:?host[localhost]&host[localhost:12345]', MemcachedStore::class];
6162
}
62-
if (class_exists(\Redis::class) && class_exists(AbstractAdapter::class)) {
63+
if ((class_exists(\Redis::class) || class_exists(\Predis\Client::class)) && class_exists(AbstractAdapter::class)) {
6364
yield ['redis://localhost', RedisStore::class];
6465
yield ['redis://localhost?lazy=1', RedisStore::class];
6566
yield ['redis://localhost?redis_cluster=1', RedisStore::class];
6667
yield ['redis://localhost?redis_cluster=1&lazy=1', RedisStore::class];
68+
yield ['redis:?host[localhost]&host[localhost:6379]&redis_cluster=1', RedisStore::class];
6769
}
6870
if (class_exists(\PDO::class)) {
6971
yield ['sqlite:/tmp/sqlite.db', PdoStore::class];

0 commit comments

Comments
 (0)