Skip to content

Commit

Permalink
Support setting auth for RedisSentinel. (#4646)
Browse files Browse the repository at this point in the history
  • Loading branch information
sy-records authored Mar 30, 2022
1 parent dea5124 commit c983a64
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions publish/redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
'nodes' => explode(';', env('REDIS_SENTINEL_NODE', '')),
'persistent' => '',
'read_timeout' => 0,
'auth' => null,
],
'pool' => [
'min_connections' => 1,
Expand Down
4 changes: 3 additions & 1 deletion src/RedisConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ protected function createRedisSentinel()
$retryInterval = $this->config['retry_interval'] ?? 0;
$readTimeout = $this->config['sentinel']['read_timeout'] ?? 0;
$masterName = $this->config['sentinel']['master_name'] ?? '';
$auth = $this->config['sentinel']['auth'] ?? null;
shuffle($nodes);

$host = null;
Expand All @@ -221,7 +222,8 @@ protected function createRedisSentinel()
$timeout,
$persistent,
$retryInterval,
$readTimeout
$readTimeout,
$auth
);
$masterInfo = $sentinel->getMasterAddrByName($masterName);
if (is_array($masterInfo) && count($masterInfo) >= 2) {
Expand Down
12 changes: 12 additions & 0 deletions tests/RedisTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,18 @@ public function testShuffleNodes()
$this->assertSame(3, count($nodes));
}

public function testRedisSentinelParams()
{
$rel = new \ReflectionClass(\RedisSentinel::class);
$method = $rel->getMethod('__construct');
$count = count($method->getParameters());
if ($count === 6) {
$this->markTestIncomplete('RedisSentinel don\'t support auth.');
}

$this->assertSame(7, $count);
}

private function getRedis()
{
$container = $this->getContainer();
Expand Down

0 comments on commit c983a64

Please sign in to comment.