Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.x] Adding support for using a different Redis DB in a Sentinel setup #38764

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Illuminate/Redis/RedisManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Illuminate\Redis\Connectors\PhpRedisConnector;
use Illuminate\Redis\Connectors\PredisConnector;
use Illuminate\Support\ConfigurationUrlParser;
use Illuminate\Support\Arr;
use InvalidArgumentException;

/**
Expand Down Expand Up @@ -108,7 +109,7 @@ public function resolve($name = null)
if (isset($this->config[$name])) {
return $this->connector()->connect(
$this->parseConnectionConfiguration($this->config[$name]),
$options
array_merge(Arr::except($options, 'parameters'), ['parameters' => Arr::get($options, 'parameters.'.$name, Arr::get($options, 'parameters', []))])
);
}

Expand Down
26 changes: 26 additions & 0 deletions tests/Redis/RedisConnectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,30 @@ public function testPredisConfigurationWithUsername()
$this->assertEquals($username, $parameters->username);
$this->assertEquals($password, $parameters->password);
}

public function testPredisConfigurationWithSentinel()
{
$host = env('REDIS_HOST', '127.0.0.1');
$port = env('REDIS_PORT', 6379);

$predis = new RedisManager(new Application, 'predis', [
'cluster' => false,
'options' => [
'replication' => 'sentinel',
'service' => 'mymaster',
'parameters' => [
'default' => [
'database' => 5,
]
]
],
'default' => [
"tcp://{$host}:{$port}",
],
]);

$predisClient = $predis->connection()->client();
$parameters = $predisClient->getConnection()->getSentinelConnection()->getParameters();
$this->assertEquals($host, $parameters->host);
}
}