diff --git a/bin/rqgenload b/bin/rqgenload index 8aaf46e..a6e4cfd 100755 --- a/bin/rqgenload +++ b/bin/rqgenload @@ -1,6 +1,6 @@ #!/usr/bin/env python import optparse -from rq import use_redis, Queue, Worker +from rq import use_connection, Queue, Worker from rq import dummy @@ -16,7 +16,7 @@ def main(): opts, args, parser = parse_args() - use_redis() + use_connection() queues = ('default', 'high', 'low') diff --git a/bin/rqinfo b/bin/rqinfo index 8c5f3f1..06e8192 100755 --- a/bin/rqinfo +++ b/bin/rqinfo @@ -6,7 +6,7 @@ import time import argparse import redis from redis.exceptions import ConnectionError -from rq import use_redis, Queue, Worker +from rq import use_connection, Queue, Worker from rq.utils import gettermsize, make_colorizer red = make_colorizer('darkred') @@ -146,7 +146,7 @@ def main(): # Setup connection to Redis redis_conn = redis.Redis(host=args.host, port=args.port, db=args.db) - use_redis(redis_conn) + use_connection(redis_conn) try: args.func(args) except ConnectionError as e: diff --git a/bin/rqworker b/bin/rqworker index 3d390fd..e6a72e2 100755 --- a/bin/rqworker +++ b/bin/rqworker @@ -4,7 +4,7 @@ import argparse import logbook import redis from logbook import handlers -from rq import use_redis, Queue, Worker +from rq import use_connection, Queue, Worker from redis.exceptions import ConnectionError @@ -64,7 +64,7 @@ def main(): # Setup connection to Redis redis_conn = redis.Redis(host=args.host, port=args.port, db=args.db) - use_redis(redis_conn) + use_connection(redis_conn) try: queues = map(Queue, args.queues) w = Worker(queues, name=args.name) diff --git a/rq/__init__.py b/rq/__init__.py index f70e950..40ea226 100644 --- a/rq/__init__.py +++ b/rq/__init__.py @@ -7,10 +7,6 @@ from .worker import Worker from .version import VERSION -def use_redis(redis=None): - use_connection(redis) - - __all__ = [ 'use_connection', 'get_current_connection', 'push_connection', 'pop_connection', 'Connection', diff --git a/rq/connections.py b/rq/connections.py index 4087d41..c714a35 100644 --- a/rq/connections.py +++ b/rq/connections.py @@ -60,13 +60,16 @@ def pop_connection(): return _connection_stack.pop() -def use_connection(redis): +def use_connection(redis=None): """Clears the stack and uses the given connection. Protects against mixed use of use_connection() and stacked connection contexts. """ assert _connection_stack.depth() <= 1, \ 'You should not mix Connection contexts with use_connection().' _connection_stack.empty() + + if redis is None: + redis = Redis() push_connection(redis)