8000 [Cache] Fix two initializations of Redis Sentinel · symfony/symfony@2d23a1b · GitHub
[go: up one dir, main page]

Skip to content

Commit 2d23a1b

Browse files
committed
[Cache] Fix two initializations of Redis Sentinel
1 parent 3c4cfbd commit 2d23a1b

File tree

1 file changed

+20
-21
lines changed

1 file changed

+20
-21
lines changed

src/Symfony/Component/Cache/Traits/RedisTrait.php

+20-21
Original file line numberDiff line numberDiff line change
@@ -223,29 +223,28 @@ public static function createConnection(#[\SensitiveParameter] string $dsn, arra
223223
break;
224224
}
225225

226-
if (version_compare(phpversion('redis'), '6.0.0', '>=') && $isRedisExt) {
227-
$options = [
228-
'host' => $host,
229-
'port' => $port,
230-
'connectTimeout' => $params['timeout'],
231-
'persistent' => $params['persistent_id'],
232-
'retryInterval' => $params['retry_interval'],
233-
'readTimeout' => $params['read_timeout'],
234-
];
235-
236-
if ($passAuth) {
237-
$options['auth'] = $params['auth'];
226+
try {
227+
if (version_compare(phpversion('redis'), '6.0.0', '>=') && $isRedisExt) {
228+
$options = [
229+
'host' => $host,
230+
'port' => $port,
231+
'connectTimeout' => $params['timeout'],
232+
'persistent' => $params['persistent_id'],
233+
'retryInterval' => $params['retry_interval'],
234+
'readTimeout' => $params['read_timeout'],
235+
];
236+
237+
if ($passAuth) {
238+
$options['auth'] = $params['auth'];
239+
}
240+
241+
$sentinel = new \RedisSentinel($options);
242+
} else {
243+
$extra = $passAuth ? [$params['auth']] : [];
244+
245+
$sentinel = new $sentinelClass($host, $port, $params['timeout'], (string) $params['persistent_id'], $params['retry_interval'], $params['read_timeout'], ...$extra);
238246
}
239247

240-
$sentinel = new \RedisSentinel($options);
241-
} else {
242-
$extra = $passAuth ? [$params['auth']] : [];
243-
244-
$sentinel = new $sentinelClass($host, $port, $params['timeout'], (string) $params['persistent_id'], $params['retry_interval'], $params['read_timeout'], ...$extra);
245-
}
246-
247-
try {
248-
$sentinel = new $sentinelClass($host, $port, $params['timeout'], (string) $params['persistent_id'], $params['retry_interval'], $params['read_timeout'], ...$extra);
249248
if ($address = $sentinel->getMasterAddrByName($params['redis_sentinel'])) {
250249
[$host, $port] = $address;
251250
}

0 commit comments

Comments
 (0)
0