我不清楚连接池如何工作,以及如何正确使用它们.我希望有人可以详细说明.我在下面勾勒出我的用例:
settings.py:
import redis
def get_redis_connection():
return redis.StrictRedis(host='localhost', port=6379, db=0)
Run Code Online (Sandbox Code Playgroud)
task1.py
import settings
connection = settings.get_redis_connection()
def do_something1():
return connection.hgetall(...)
Run Code Online (Sandbox Code Playgroud)
task2.py
import settings
connection = settings.get_redis_connection()
def do_something1():
return connection.hgetall(...)
Run Code Online (Sandbox Code Playgroud)
等等
基本上我有一个返回redis连接的setting.py文件,以及几个获取redis连接的不同任务文件,然后运行操作.因此每个任务文件都有自己的redis实例(可能非常昂贵).优化此过程的最佳方法是什么?是否可以在此示例中使用连接池?有没有更有效的方法来设置这种模式?
对于我们的系统,我们有相同模式的十几个任务文件,我注意到我们的请求减慢了.
谢谢