Skip to content

Commit 9423c71

Browse files
Qonstruktnicolas-grekas
authored andcommitted
[Cache] Fix support for Redis Sentinel using php-redis 6.0.0
1 parent 7c4f174 commit 9423c71

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

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

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ public static function createConnection(string $dsn, array $options = [])
202202
do {
203203
$host = $hosts[$hostIndex]['host'] ?? $hosts[$hostIndex]['path'];
204204
$port = $hosts[$hostIndex]['port'] ?? 0;
205+
$passAuth = \defined('Redis::OPT_NULL_MULTIBULK_AS_NULL') && isset($params['auth']);
205206
$address = false;
206207

207208
if (isset($hosts[$hostIndex]['host']) && $tls) {
@@ -211,11 +212,27 @@ public static function createConnection(string $dsn, array $options = [])
211212
if (!isset($params['redis_sentinel'])) {
212213
break;
213214
}
214-
$extra = [];
215-
if (\defined('Redis::OPT_NULL_MULTIBULK_AS_NULL') && isset($params['auth'])) {
216-
$extra = [$params['auth']];
215+
216+
if (version_compare(phpversion('redis'), '6.0.0', '>=')) {
217+
$options = [
218+
'host' => $host,
219+
'port' => $port,
220+
'connectTimeout' => $params['timeout'],
221+
'persistent' => $params['persistent_id'],
222+
'retryInterval' => $params['retry_interval'],
223+
'readTimeout' => $params['read_timeout'],
224+
];
225+
226+
if ($passAuth) {
227+
$options['auth'] = $params['auth'];
228+
}
229+
230+
$sentinel = new \RedisSentinel($options);
231+
} else {
232+
$extra = $passAuth ? [$params['auth']] : [];
233+
234+
$sentinel = new \RedisSentinel($host, $port, $params['timeout'], (string) $params['persistent_id'], $params['retry_interval'], $params['read_timeout'], ...$extra);
217235
}
218-
$sentinel = new \RedisSentinel($host, $port, $params['timeout'], (string) $params['persistent_id'], $params['retry_interval'], $params['read_timeout'], ...$extra);
219236

220237
try {
221238
if ($address = $sentinel->getMasterAddrByName($params['redis_sentinel'])) {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy