Skip to content

Commit 257a5a8

Browse files
Fixed bug that RedisSentinel can't support empty password. (#5199)
Co-authored-by: 李铭昕 <[email protected]>
1 parent 965415f commit 257a5a8

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

publish/redis.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
'nodes' => explode(';', env('REDIS_SENTINEL_NODE', '')),
3131
'persistent' => '',
3232
'read_timeout' => 0,
33-
'auth' => null,
33+
'auth' => env('REDIS_SENTINEL_PASSWORD', ''),
3434
],
3535
'pool' => [
3636
'min_connections' => 1,

src/RedisConnection.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,13 @@ protected function createRedisSentinel(): Redis
212212
$readTimeout = $this->config['sentinel']['read_timeout'] ?? 0;
213213
$masterName = $this->config['sentinel']['master_name'] ?? '';
214214
$auth = $this->config['sentinel']['auth'] ?? null;
215+
// fixes bug for phpredis
216+
// https://github.com/phpredis/phpredis/issues/2098
217+
$extendConfig = [];
218+
if (! empty($auth)) {
219+
$extendConfig[] = $auth;
220+
}
221+
215222
shuffle($nodes);
216223

217224
$host = null;
@@ -226,7 +233,7 @@ protected function createRedisSentinel(): Redis
226233
$persistent,
227234
$retryInterval,
228235
$readTimeout,
229-
$auth
236+
...$extendConfig
230237
);
231238
$masterInfo = $sentinel->getMasterAddrByName($masterName);
232239
if (is_array($masterInfo) && count($masterInfo) >= 2) {
@@ -266,7 +273,7 @@ protected function createRedis(array $config): Redis
266273
{
267274
$parameters = [
268275
$config['host'] ?? '',
269-
$config['port'] ?? 6379,
276+
(int) ($config['port'] ?? 6379),
270277
$config['timeout'] ?? 0.0,
271278
$config['reserved'] ?? null,
272279
$config['retry_interval'] ?? 0,

0 commit comments

Comments
 (0)