mirror of https://github.com/peter4431/rq.git
Add better connection management.
To start using RQ, push a Redis connection up its stack, like so: from rq import push_connection push_connection(Redis())main
parent
d8d388c841
commit
518db8c24b
@ -0,0 +1,18 @@
|
|||||||
|
from werkzeug.local import LocalStack
|
||||||
|
|
||||||
|
class NoRedisConnectionException(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
_conn = LocalStack()
|
||||||
|
|
||||||
|
def push_connection(redis_conn):
|
||||||
|
_conn.push(redis_conn)
|
||||||
|
|
||||||
|
def pop_connection():
|
||||||
|
return _conn.pop()
|
||||||
|
|
||||||
|
def current_connection():
|
||||||
|
conn = _conn.top
|
||||||
|
if conn is None:
|
||||||
|
raise NoRedisConnectionException('Connect to Redis first.')
|
||||||
|
return conn
|
Loading…
Reference in New Issue