Closed jab1000 closed 4 years ago
Hi @jab1000,
It looks like you want to use Sentinel connections for your application's queues and for Horizon. There are some problems with the configuration that you posted. To enable the Sentinel connection for the queue, we need these directives in .env:
QUEUE_CONNECTION=redis-sentinel
REDIS_DRIVER=redis-sentinel
REDIS_HOST=sentinel-ip1,sentinel-ip2,sentinel-ip3,...
REDIS_PORT=26379
REDIS_SENTINEL_SERVICE=mymaster
REDIS_QUEUE_DATABASE=3
We use the REDIS_HOST
and REDIS_PORT
environment variables here instead of REDIS_SENTINEL_HOST
and REDIS_SENTINEL_PORT
because you set REDIS_DRIVER=redis-sentinel
, so I assume that you want the whole application to use Sentinel connections. Note that we want to provide the IP addresses or hostnames of the Sentinel servers, not the Redis servers that they monitor (set the master in your sentinel.conf file).
The package will automatically set up a Sentinel connection for the queue named database.redis-sentinel.queue
. It will also define the queue.connections.redis-sentinel
queue connection for us, but since you're using some non-default options, we need to override that connection in config/queue.php:
'connections' => [
...
'redis-sentinel' => [
'driver' => 'redis-sentinel',
'connection' => env('QUEUE_REDIS_CONNECTION', 'queue'),
'queue' => 'default',
'retry_after' => 3666,
'expire' => 3666, // Legacy, Laravel < 5.4.30
],
],
The queue will now run using Sentinel connections. Since you set REDIS_DRIVER=redis-sentinel
, Horizon will also use Sentinel connections automatically, but we need to define a specific connection for Horizon in config/database.php because you want a separate database number for Horizon:
'redis-sentinel' => [
'queue' => [ ... ],
'horizon' => [
[
'host' => env('REDIS_HOST', 'localhost'),
'port' => env('REDIS_PORT', 26379),
],
'options' => [
'service' => env('REDIS_SENTINEL_SERVICE', 'mymaster'),
'parameters' => [
'password' => env('REDIS_PASSWORD', null),
'database' => env('REDIS_HORIZON_DB', 0),
],
],
],
],
Note that we also need to define the queue connection here now because adding an explicit connection configuration block for the package's Sentinel connections disables the automatic configuration.
Change 'use' => 'default'
to 'horizon'
in config/horizon.php and add a matching connection to the 'redis'
connections array in config/database.php (this is currently a limitation of Horizon):
'redis' => [
...
'horizon' => [ ... ],
],
Finally, your configuration contains some options for Redis Cluster. Be aware that this is a different clustering system than Redis Sentinel, and that this package does not target Redis Cluster. This directive is invalid and has no effect:
REDIS_CLUSTER=redis-sentinel
...but interesting thing is we can't run a "sentinel command" from CLI either. I CAN though on the CLI run it with Redis-cli first like this: redis-cli -p 26379 sentinel slaves mymaster
This package's API provides an interface to the Redis servers monitored by Sentinel (the master and replicas that contain the data), not to the Sentinel servers themselves. We can send commands to the Sentinels directly by obtaining a connection to a Sentinel server from the package's connection manager:
use Predis\Command\RawCommand;
...
$sentinel = app('redis-sentinel')->client()->getConnection()->getSentinelConnection();
$command = RawCommand::create('SENTINEL', 'slaves', 'mymaster');
$sentinel->executeCommand($command);
I'm working on an API for low-level Sentinel commands that may become part of this package in the future.
Closing—please comment if you believe this is still an issue.
I have a Redis Sentinel cluster for our production servers -- the web servers have been running for the past year and have had zero issues. Tried originally to setup Horizon to use our cluster but wasn't ever able to originally, but decided it was time to try again.
official error: production.ERROR: ERR unknown command 'SENTINEL' {"exception":"[object] (Predis\Response\ServerException(code: 0): ERR unknown command 'SENTINEL' at /var/www/tennispoint/vendor/predis/predis/src/Connection/Aggregate/SentinelReplication.php:332)
Yes, we are running Sentinel on all 3 Redis Servers, but interesting thing is we can't run a "sentinel command" from CLI either. I CAN though on the CLI run it with Redis-cli first like this: redis-cli -p 26379 sentinel slaves mymaster
If it is a "redis sentinel server setup" weird though production servers never complain for cache, session, etc stored there.
From what I can tell all is configured correctly for our "Horizon server" and since our "non-horizon laravel" servers aren't having in issue with Redis Sentinel wondering if something else?
To be sure here is our configs overall - Laravel 6.x & latest laravel-redis-sentinel package
My .env file contains:
My database.php file contains:
My Horizon.php file contains:
My Queue.php file contains the following:
Just in case, here is the full stack trace: