Fixed bug that RedisSentinel can't support empty password. (#5199)

Co-authored-by: 李铭昕 <715557344@qq.com>
This commit is contained in:
宣言就是Siam 2022-11-16 10:16:48 +08:00 committed by GitHub
parent 972b9d0a9a
commit 67fec55758
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 4 deletions

View File

@ -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.

View File

@ -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;

View File

@ -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,

View File

@ -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,