Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c0fbe7f

Browse files
bug #51683 [Cache] Fix support for Redis Sentinel using php-redis 6.0.0 (Qonstrukt)
This PR was squashed before being merged into the 5.4 branch. Discussion ---------- [Cache] Fix support for Redis Sentinel using php-redis 6.0.0 | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #51678 | License | MIT Added support for [php-redis 6.0.0](https://github.com/phpredis/phpredis/blob/develop/CHANGELOG.md#600---2023-09-09-github-pecl) to `Symfony/Component/Cache/Traits/RedisTrait`. Made changes to how `RedisSentinel` is constructed, which now uses [the same constructor](phpredis/phpredis@ebb2386e) as the main `Redis` class. Didn't find any other changes that might be relevant yet, but it's why I mention Redis Sentinel explicitly. Commits ------- 9423c71 [Cache] Fix support for Redis Sentinel using php-redis 6.0.0
2 parents 1de61c7 + 9423c71 commit c0fbe7f

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)