summaryrefslogtreecommitdiff
path: root/rq
diff options
context:
space:
mode:
authorJoachim Burket <joachimBurket@users.noreply.github.com>2023-03-07 04:03:31 +0100
committerGitHub <noreply@github.com>2023-03-07 10:03:31 +0700
commit7f9f0f72ba1adac907791d604d5f56af8125fdfd (patch)
treed6977cfafac350140c2cb5c66b7585756c497b01 /rq
parent82a59e9791335fcdd263fda2799aa126ddce4e90 (diff)
downloadrq-7f9f0f72ba1adac907791d604d5f56af8125fdfd.tar.gz
Update arguments passed to the Sentinel Object when created from the settings (#1850)
* Updated arguments passed to the Sentinel Object when created from the settings - added `USERNAME` key - added `CONNECTION_KWARGS` key to allow passing additionals arguments to the Redis connections - updated the documentation * added missing comma * tests(helpers): Added tests for Sentinel --------- Co-authored-by: Joachim Burket <joachim.burket@hopitalvs.ch>
Diffstat (limited to 'rq')
-rw-r--r--rq/cli/helpers.py20
1 files changed, 13 insertions, 7 deletions
diff --git a/rq/cli/helpers.py b/rq/cli/helpers.py
index 53bc019..0f87d22 100644
--- a/rq/cli/helpers.py
+++ b/rq/cli/helpers.py
@@ -33,21 +33,27 @@ def get_redis_from_config(settings, connection_class=Redis):
"""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':}
+ SENTINEL = {'INSTANCES':, 'SOCKET_TIMEOUT':, 'USERNAME':, 'PASSWORD':, 'DB':, 'MASTER_NAME':, 'SENTINEL_KWARGS':}
"""
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')
- ssl = settings['SENTINEL'].get('SSL', False)
- arguments = {'password': password, 'ssl': ssl}
+
+ connection_kwargs = {
+ 'db': settings['SENTINEL'].get('DB', 0),
+ 'username': settings['SENTINEL'].get('USERNAME', None),
+ 'password': settings['SENTINEL'].get('PASSWORD', None),
+ 'socket_timeout': settings['SENTINEL'].get('SOCKET_TIMEOUT', None),
+ 'ssl': settings['SENTINEL'].get('SSL', False),
+ }
+ connection_kwargs.update(settings['SENTINEL'].get('CONNECTION_KWARGS', {}))
+ sentinel_kwargs = settings['SENTINEL'].get('SENTINEL_KWARGS', {})
+
sn = Sentinel(
- instances, socket_timeout=socket_timeout, password=password, db=db, ssl=ssl, sentinel_kwargs=arguments
+ instances, sentinel_kwargs=sentinel_kwargs, **connection_kwargs
)
return sn.master_for(master_name)