Permalink
Browse files

Merge pull request #741 from rq-cluster/rxl-sentinel

custom connection class
  • Loading branch information...
2 parents 69b43da + ee4cf6e commit d2674898e4cdc80633500a7d84bfa31fcf7aa444 @selwin selwin committed on GitHub Aug 23, 2016
Showing with 10 additions and 8 deletions.
  1. +7 −5 rq/cli/cli.py
  2. +3 −3 rq/cli/helpers.py
View
12 rq/cli/cli.py
@@ -37,12 +37,12 @@
help='Module containing RQ settings.')
-def connect(url, config=None):
+def connect(url, config=None, connection_class=StrictRedis):
if url:
- return StrictRedis.from_url(url)
+ return connection_class.from_url(url)
settings = read_config_file(config) if config else {}
- return get_redis_from_config(settings)
+ return get_redis_from_config(settings, connection_class)
@click.group()
@@ -143,6 +143,7 @@ def info(url, config, path, interval, raw, only_queues, only_workers, by_queue,
@click.option('--worker-class', '-w', default='rq.Worker', help='RQ Worker class to use')
@click.option('--job-class', '-j', default='rq.job.Job', help='RQ Job class to use')
@click.option('--queue-class', default='rq.Queue', help='RQ Queue class to use')
+@click.option('--connection-class', default='redis.StrictRedis', help='Redis client class to use')
@click.option('--path', '-P', default='.', help='Specify the import path.')
@click.option('--results-ttl', type=int, help='Default results timeout to be used')
@click.option('--worker-ttl', type=int, help='Default worker timeout to be used')
@@ -152,7 +153,7 @@ def info(url, config, path, interval, raw, only_queues, only_workers, by_queue,
@click.option('--exception-handler', help='Exception handler(s) to use', multiple=True)
@click.option('--pid', help='Write the process ID number to a file at the specified path')
@click.argument('queues', nargs=-1)
-def worker(url, config, burst, name, worker_class, job_class, queue_class, path, results_ttl, worker_ttl,
+def worker(url, config, burst, name, worker_class, job_class, queue_class, connection_class, path, results_ttl, worker_ttl,
verbose, quiet, sentry_dsn, exception_handler, pid, queues):
"""Starts an RQ worker."""
@@ -170,7 +171,8 @@ def worker(url, config, burst, name, worker_class, job_class, queue_class, path,
setup_loghandlers_from_args(verbose, quiet)
- conn = connect(url, config)
+ connection_class = import_attribute(connection_class)
+ conn = connect(url, config, connection_class)
cleanup_ghosts(conn)
worker_class = import_attribute(worker_class)
queue_class = import_attribute(queue_class)
View
6 rq/cli/helpers.py
@@ -26,10 +26,10 @@ def read_config_file(module):
if k.upper() == k])
-def get_redis_from_config(settings):
+def get_redis_from_config(settings, connection_class=StrictRedis):
"""Returns a StrictRedis instance from a dictionary of settings."""
if settings.get('REDIS_URL') is not None:
- return StrictRedis.from_url(settings['REDIS_URL'])
+ return connection_class.from_url(settings['REDIS_URL'])
kwargs = {
'host': settings.get('REDIS_HOST', 'localhost'),
@@ -52,7 +52,7 @@ def safeint(x):
if not version_info >= (2, 10):
raise RuntimeError('Using SSL requires a redis-py version >= 2.10')
kwargs['ssl'] = use_ssl
- return StrictRedis(**kwargs)
+ return connection_class(**kwargs)
def pad(s, pad_to_length):

0 comments on commit d267489

Please sign in to comment.