From 1029adaf1b811bbeb11f0f67844f1599007cb047 Mon Sep 17 00:00:00 2001 From: strawposter Date: Mon, 10 Apr 2017 12:34:12 +0300 Subject: [PATCH] add sentinel support (#808) * add sentinel support * add sentinel support * add comment --- rq/cli/helpers.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/rq/cli/helpers.py b/rq/cli/helpers.py index c271174..ed28aba 100644 --- a/rq/cli/helpers.py +++ b/rq/cli/helpers.py @@ -9,6 +9,7 @@ from functools import partial import click import redis from redis import StrictRedis +from redis.sentinel import Sentinel from rq.defaults import (DEFAULT_CONNECTION_CLASS, DEFAULT_JOB_CLASS, DEFAULT_QUEUE_CLASS, DEFAULT_WORKER_CLASS) from rq.logutils import setup_loghandlers @@ -29,10 +30,23 @@ def read_config_file(module): def get_redis_from_config(settings, connection_class=StrictRedis): - """Returns a StrictRedis instance from a dictionary of settings.""" + """Returns a StrictRedis instance from a dictionary of settings. + To use redis sentinel, you must specify a dictionary in the configuration file. + Example of a dictionary with keys without values: + SENTINEL: {'INSTANCES':, 'SOCKET_TIMEOUT':, 'PASSWORD':,'DB':, 'MASTER_NAME':} + """ if settings.get('REDIS_URL') is not None: return connection_class.from_url(settings['REDIS_URL']) + elif settings.get('SENTINEL') is not None: + instances = settings['SENTINEL'].get('INSTANCES', [('localhost', 26379)]) + socket_timeout = settings['SENTINEL'].get('SOCKET_TIMEOUT', None) + password = settings['SENTINEL'].get('PASSWORD', None) + db = settings['SENTINEL'].get('DB', 0) + master_name = settings['SENTINEL'].get('MASTER_NAME', 'mymaster') + sn = Sentinel(instances, socket_timeout=socket_timeout, password=password, db=db) + return sn.master_for(master_name) + kwargs = { 'host': settings.get('REDIS_HOST', 'localhost'), 'port': settings.get('REDIS_PORT', 6379),