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
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public function testInvalidCreateConnection(string $dsn)
public function provideInvalidCreateConnection(): array
{
return [
['redis://localhost/foo'],
['foo://localhost'],
['redis://'],
];
Expand Down
10 changes: 7 additions & 3 deletions src/Symfony/Component/Cache/Traits/RedisTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,13 @@ public static function createConnection($dsn, array $options = [])
}

if (isset($params['host']) || isset($params['path'])) {
if (!isset($params['dbindex']) && isset($params['path']) && preg_match('#/(\d+)$#', $params['path'], $m)) {
$params['dbindex'] = $m[1];
$params['path'] = substr($params['path'], 0, -\strlen($m[0]));
if (!isset($params['dbindex']) && isset($params['path'])) {
if (preg_match('#/(\d+)$#', $params['path'], $m)) {
$params['dbindex'] = $m[1];
$params['path'] = substr($params['path'], 0, -\strlen($m[0]));
} else {
throw new InvalidArgumentException(sprintf('Invalid Redis DSN: "%s", the "dbindex" parameter must be a number.', $dsn));
}
}

if (isset($params['host'])) {
Expand Down