Skip to content

Commit 69f1a6e

Browse files
authored
Fixed redis cluster does not support auth. (#2632)
1 parent 704d654 commit 69f1a6e

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/RedisConnection.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ class RedisConnection extends BaseConnection implements ConnectionInterface
4343
'enable' => false,
4444
'name' => null,
4545
'seeds' => [],
46+
'read_timeout' => 0.0,
47+
'persistent' => false,
4648
],
4749
'sentinel' => [
4850
'enable' => false,
@@ -122,7 +124,7 @@ public function reconnect(): bool
122124
$redis->setOption($name, $value);
123125
}
124126

125-
if (isset($auth) && $auth !== '') {
127+
if ($redis instanceof \Redis && isset($auth) && $auth !== '') {
126128
$redis->auth($auth);
127129
}
128130

@@ -164,9 +166,12 @@ protected function createRedisCluster()
164166
try {
165167
$seeds = $this->config['cluster']['seeds'] ?? [];
166168
$name = $this->config['cluster']['name'] ?? null;
169+
$readTimeout = $this->config['cluster']['read_timeout'] ?? null;
170+
$persistent = $this->config['cluster']['persistent'] ?? false;
167171
$timeout = $this->config['timeout'] ?? null;
172+
$auth = $this->config['auth'] ?? null;
168173

169-
$redis = new \RedisCluster($name, $seeds, $timeout);
174+
$redis = new \RedisCluster($name, $seeds, $timeout, $readTimeout, $persistent, $auth);
170175
} catch (\Throwable $e) {
171176
throw new ConnectionException('Connection reconnect failed ' . $e->getMessage());
172177
}

tests/RedisConnectionTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ public function testRedisConnectionConfig()
5050
'enable' => false,
5151
'name' => null,
5252
'seeds' => [],
53+
'read_timeout' => 0.0,
54+
'persistent' => false,
5355
],
5456
'sentinel' => [
5557
'enable' => false,

0 commit comments

Comments
 (0)