Should two modules use the same redis connection? (I'm working with Flask)

我只是一个虾纸丫 提交于 2019-12-11 04:06:04

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!