Skip to content

Commit c983a64

Browse files
authored
Support setting auth for RedisSentinel. (#4646)
1 parent dea5124 commit c983a64

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

publish/redis.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
'nodes' => explode(';', env('REDIS_SENTINEL_NODE', '')),
3030
'persistent' => '',
3131
'read_timeout' => 0,
32+
'auth' => null,
3233
],
3334
'pool' => [
3435
'min_connections' => 1,

src/RedisConnection.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ protected function createRedisSentinel()
208208
$retryInterval = $this->config['retry_interval'] ?? 0;
209209
$readTimeout = $this->config['sentinel']['read_timeout'] ?? 0;
210210
$masterName = $this->config['sentinel']['master_name'] ?? '';
211+
$auth = $this->config['sentinel']['auth'] ?? null;
211212
shuffle($nodes);
212213

213214
$host = null;
@@ -221,7 +222,8 @@ protected function createRedisSentinel()
221222
$timeout,
222223
$persistent,
223224
$retryInterval,
224-
$readTimeout
225+
$readTimeout,
226+
$auth
225227
);
226228
$masterInfo = $sentinel->getMasterAddrByName($masterName);
227229
if (is_array($masterInfo) && count($masterInfo) >= 2) {

tests/RedisTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,18 @@ public function testShuffleNodes()
182182
$this->assertSame(3, count($nodes));
183183
}
184184

185+
public function testRedisSentinelParams()
186+
{
187+
$rel = new \ReflectionClass(\RedisSentinel::class);
188+
$method = $rel->getMethod('__construct');
189+
$count = count($method->getParameters());
190+
if ($count === 6) {
191+
$this->markTestIncomplete('RedisSentinel don\'t support auth.');
192+
}
193+
194+
$this->assertSame(7, $count);
195+
}
196+
185197
private function getRedis()
186198
{
187199
$container = $this->getContainer();

0 commit comments

Comments
 (0)