8000 [Lock] Fix StoreFactory to accept same DSN syntax as AbstractAdapter by Jontsa · Pull Request #36291 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Lock] Fix StoreFactory to accept same DSN syntax as AbstractAdapter #36291

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 3, 2020
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
8000 Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/Symfony/Component/Lock/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
8000
4 changes: 3 additions & 1 deletion src/Symfony/Component/Lock/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)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert this.

The purpose of this check is to avoid failing tests when the extension is not installed.

By checking if Predis is installed (which is always true because in require-dev) this breaks the initial check.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in 6a79f3e

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