-
Notifications
You must be signed in to change notification settings - Fork 11.2k
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
Added ability to use Redis Sentinel configuration #18850
Conversation
These changes make it possible to use Redis Sentinel with Laravel/Lumen and Predis, configuration example: ``` return [ // ... 'redis' => [ 'client' => 'predis', 'sentinel' => [ 'tcp://10.24.5.136:26379?timeout=0.100', 'tcp://10.24.5.137:26379?timeout=0.100', 'tcp://10.24.5.138:26379?timeout=0.100', 'options' => [ 'replication' => 'sentinel', 'service' => env('REDIS_SENTINEL_SERVICE', 'mymaster'), 'parameters' => [ 'password' => env('REDIS_PASSWORD', null), 'database' => 0, ], ], ], ], ]; ``` It's very important to call Arr::pull($config, 'options', []) before passing it to Client.
Add the sentinel config from laravel/framework#18850 to docs.
What will be the default key settings? |
@CharlesBilbo @taylorotwell I am trying your configuration in 2021 and it's working. Thank you so much. Please, I have a few questions By default in Laravel we have the 'cache configuration', how would you setup your cache configuration with Redis Sentinel Also, I would like to ask why do you have the same value 'tcp://127.0.0.1:26379?timeout=0.1' on 3 different lines in your default configuration? I do have there different sentinels running on three different ports |
Let me conribute with another working config (running in 2022 with laravel 8.x) This includes "private" options that allows to choose different database id and prefix, which is very important in case of shared redis instances. config/database.php <?php
return [
//...
'redis' => [
'client' => 'predis',
'default' => [
'tcp://' . env('REDIS_HOST') . ':' . env('REDIS_PORT') . '?timeout=0.1',
'tcp://' . env('REDIS_HOST_n') . ':' . env('REDIS_PORT') . '?timeout=0.1',
'options' => [
'replication' => 'sentinel',
'service' => 'mymaster',
'parameters' => [
'password' => env('REDIS_PASSWORD'),
'database' => env('REDIS_DB', 0)],
'prefix' => 'myapp:',
],
],
],
'cache' => [
'tcp://' . env('REDIS_HOST') . ':' . env('REDIS_PORT') . '?timeout=0.1',
'tcp://' . env('REDIS_HOST_n') . ':' . env('REDIS_PORT') . '?timeout=0.1',
'options' => [
'replication' => 'sentinel',
'service' => 'mymaster',
'parameters' => [
'password' => env('REDIS_PASSWORD'),
'database' => env('REDIS_CACHE_DB', 1)
'prefix' => 'myappcache:',
],
],
],
],
]; |
Thanks @skiat but your example appears to be broken. Is there a closing bracket missing for 'default.parameters'? |
@DreadfulCode Yeah seems like there is a closing bracket missing @Olayiwola72 Each TCP address in that array is a different redis sentential server. instance they way sentinel works is their one main server and 2 observers. |
Thanks, yes, I fixed my comment. |
Does it work with phpredis too? |
Hi LyKos4 |
So from version 10, laravel doesn't support sentinel usage without additional packages, right? |
These changes make it possible to use Redis Sentinel with Laravel/Lumen and Predis, configuration example:
It's very important to call Arr::pull($config, 'options', []) before passing it to Client.