问题
I'm building a Flask app that uses a Redis Queue. The code for the worker is:
listen = ['default']
#redis_url = os.getenv('REDISTOGO_URL', 'redis://localhost:6379')
conn = redis.from_url(redis_url)
if __name__ == '__main__':
with Connection(conn):
worker = Worker(list(map(Queue, listen)))
worker.work()
And another module, app.py contains the code to handle Flask routes. My question is, should app.py create a new Redis connection as:
q = Queue(connection= redis.from_url(redis_url))
q.enqueue_call(func=mailers.send_message, kwargs=request.json, result_ttl=86400)
Or should app.py use
import conn from worker
And use that connection?
回答1:
I'd say use a new connection unless you really have a good reason not to (although I can't imagine such reason)
来源:https://stackoverflow.com/questions/29483223/should-two-modules-use-the-same-redis-connection-im-working-with-flask