From 67fec55758ac82fddee4f5e3371185b4733514a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=A3=E8=A8=80=E5=B0=B1=E6=98=AFSiam?= <59419979@qq.com> Date: Wed, 16 Nov 2022 10:16:48 +0800 Subject: [PATCH] Fixed bug that `RedisSentinel` can't support empty password. (#5199) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 李铭昕 <715557344@qq.com> --- CHANGELOG-3.0.md | 1 + src/async-queue/src/Process/ConsumerProcess.php | 1 - src/redis/publish/redis.php | 2 +- src/redis/src/RedisConnection.php | 11 +++++++++-- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/CHANGELOG-3.0.md b/CHANGELOG-3.0.md index bf05dca17..2fd5ad852 100644 --- a/CHANGELOG-3.0.md +++ b/CHANGELOG-3.0.md @@ -164,3 +164,4 @@ composer analyse - [#5100](https://github.com/hyperf/hyperf/pull/5100) Fixed bug that the tag `continue` cannot work when using `view-engine`. - [#5121](https://github.com/hyperf/hyperf/pull/5121) Fixed bug that the SQL is not valid but the correct error message cannot be obtained when using `pgsql`. - [#5132](https://github.com/hyperf/hyperf/pull/5132) Fixed bug that the exit code of command does not work when the exception code isn't int. +- [#5199](https://github.com/hyperf/hyperf/pull/5199) Fixed bug that `RedisSentinel` can't support empty password. diff --git a/src/async-queue/src/Process/ConsumerProcess.php b/src/async-queue/src/Process/ConsumerProcess.php index 4d599a83f..7980bef79 100644 --- a/src/async-queue/src/Process/ConsumerProcess.php +++ b/src/async-queue/src/Process/ConsumerProcess.php @@ -13,7 +13,6 @@ namespace Hyperf\AsyncQueue\Process; use Hyperf\AsyncQueue\Driver\DriverFactory; use Hyperf\AsyncQueue\Driver\DriverInterface; -use Hyperf\Contract\StdoutLoggerInterface; use Hyperf\Process\AbstractProcess; use Psr\Container\ContainerInterface; diff --git a/src/redis/publish/redis.php b/src/redis/publish/redis.php index 1b0ce3409..a25a1fb8b 100644 --- a/src/redis/publish/redis.php +++ b/src/redis/publish/redis.php @@ -30,7 +30,7 @@ return [ 'nodes' => explode(';', env('REDIS_SENTINEL_NODE', '')), 'persistent' => '', 'read_timeout' => 0, - 'auth' => null, + 'auth' => env('REDIS_SENTINEL_PASSWORD', ''), ], 'pool' => [ 'min_connections' => 1, diff --git a/src/redis/src/RedisConnection.php b/src/redis/src/RedisConnection.php index a8b005003..a53916d60 100644 --- a/src/redis/src/RedisConnection.php +++ b/src/redis/src/RedisConnection.php @@ -212,6 +212,13 @@ class RedisConnection extends BaseConnection implements ConnectionInterface $readTimeout = $this->config['sentinel']['read_timeout'] ?? 0; $masterName = $this->config['sentinel']['master_name'] ?? ''; $auth = $this->config['sentinel']['auth'] ?? null; + // fixes bug for phpredis + // https://github.com/phpredis/phpredis/issues/2098 + $extendConfig = []; + if (! empty($auth)) { + $extendConfig[] = $auth; + } + shuffle($nodes); $host = null; @@ -226,7 +233,7 @@ class RedisConnection extends BaseConnection implements ConnectionInterface $persistent, $retryInterval, $readTimeout, - $auth + ...$extendConfig ); $masterInfo = $sentinel->getMasterAddrByName($masterName); if (is_array($masterInfo) && count($masterInfo) >= 2) { @@ -266,7 +273,7 @@ class RedisConnection extends BaseConnection implements ConnectionInterface { $parameters = [ $config['host'] ?? '', - $config['port'] ?? 6379, + (int) ($config['port'] ?? 6379), $config['timeout'] ?? 0.0, $config['reserved'] ?? null, $config['retry_interval'] ?? 0,