Connecting to Redis Sentinel
RedBeat supports connecting to a Redis cluster managed by Sentinel for high availability.
To configure a Sentinel connection, you need to use the redis-sentinel:// scheme in your connection URL and provide the Sentinel host details and service name in redbeat_redis_options.
Configuration
The configuration syntax is inspired by celery-redis-sentinel.
Using REDBEAT_REDIS_URL
This is the recommended approach to avoid conflicts if your Celery broker uses a different Redis configuration.
# celeryconfig.py
REDBEAT_REDIS_URL = 'redis-sentinel://redis-sentinel:26379/0'
REDBEAT_REDIS_OPTIONS = {
'sentinels': [
('192.168.1.1', 26379),
('192.168.1.2', 26379),
('192.168.1.3', 26379)
],
'service_name': 'master', # The name of the master group in sentinel.conf
'socket_timeout': 0.1,
'password': 'your-redis-password',
'db': 0,
'sentinel_kwargs': {'password': 'your-sentinel-password'}
}
Notes:
- The hostname and port in
REDBEAT_REDIS_URLare ignored; thesentinelslist is used to establish the connection. service_nameis required and must match the name of your master group in your Sentinel configuration.passwordis the password for the Redis master/replicas.sentinel_kwargsis an optional dictionary passed to theredis.Sentinel()constructor. Use it to provide a password for the Sentinel instances themselves if they are protected.
Connection Retries
To make the connection more resilient to transient failures, you can add a retry_period to the options. RedBeat will attempt to reconnect for the specified number of seconds before failing.
REDBEAT_REDIS_OPTIONS = {
# ... other options
'retry_period': 60, # Retry connecting for 60 seconds
}
# To retry indefinitely, use -1
# 'retry_period': -1