8000 [Cache] fix dbindex Redis · symfony/cache@589395f · GitHub
[go: up one dir, main page]

Skip to content

Commit 589395f

Browse files
a1812fabpot
authored andcommitted
[Cache] fix dbindex Redis
1 parent 8d112fe commit 589395f

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

Tests/Adapter/RedisAdapterTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ public function testInvalidCreateConnection(string $dsn)
112112
public function provideInvalidCreateConnection(): array
113113
{
114114
return [
115+
['redis://localhost/foo'],
115116
['foo://localhost'],
116117
['redis://'],
117118
];

Traits/RedisTrait.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,13 @@ public static function createConnection($dsn, array $options = [])
147147
}
148148

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

155159
if (isset($params['host'])) {

0 commit comments

Comments
 (0)
0