Add a standard --url argument to all scripts.

redis-py now supports URL-based connection configuration.  When --url
is specified, we use it to construct the Redis object.  Otherwise, we
use the existing argument-based construction method.

`Redis.from_url()` is new in redis-py 2.6.2, so that prerequisite has
been adjusted accordingly.
main
Jon Parise 12 years ago
parent b97a9df69c
commit eb00f69ced

@ -5,6 +5,8 @@ from rq import use_connection
def add_standard_arguments(parser): def add_standard_arguments(parser):
parser.add_argument('--config', '-c', default=None, parser.add_argument('--config', '-c', default=None,
help='Module containing RQ settings.') help='Module containing RQ settings.')
parser.add_argument('--url', '-u', default=None,
help='URL describing Redis connection details')
parser.add_argument('--host', '-H', default=None, parser.add_argument('--host', '-H', default=None,
help='The Redis hostname (default: localhost)') help='The Redis hostname (default: localhost)')
parser.add_argument('--port', '-p', default=None, parser.add_argument('--port', '-p', default=None,
@ -44,6 +46,9 @@ def setup_default_arguments(args, settings):
def setup_redis(args): def setup_redis(args):
redis_conn = redis.Redis(host=args.host, port=args.port, db=args.db, if args.url is not None:
password=args.password) redis_conn = redis.Redis.from_url(args.url, db=args.db)
else:
redis_conn = redis.Redis(host=args.host, port=args.port, db=args.db,
password=args.password)
use_connection(redis_conn) use_connection(redis_conn)

@ -17,7 +17,7 @@ def get_version():
def get_dependencies(): def get_dependencies():
deps = ['redis >= 2.4.0', 'times'] deps = ['redis >= 2.6.2', 'times']
deps += ['logbook'] # should be soft dependency? deps += ['logbook'] # should be soft dependency?
if sys.version_info < (2, 7) or \ if sys.version_info < (2, 7) or \
(sys.version_info >= (3, 0) and sys.version_info < (3, 1)): (sys.version_info >= (3, 0) and sys.version_info < (3, 1)):

Loading…
Cancel
Save