伪代码
import redis
import settings
REDIS_ADDR='xx.xx.xx.xx'
REDIS_PORT=6379
REDIS_DB=5
REDIS_TASK=8
# 对于需要密码认证的方法
pool = redis.ConnectionPool(host=REDIS_ADDR, port=REDIS_PORT, db=0, password='your_password', max_connections=10)
redis_xxxxx = redis.Redis(connection_pool=redis_pool)
# 对不同用处的库做连接,生成对象可直接引用。
redis_pool = redis.ConnectionPool(host=REDIS_ADDR, port=REDIS_PORT, db=REDIS_DB, decode_responses=True)
redis_session = redis.Redis(connection_pool=redis_pool)
redis_pool2 = redis.ConnectionPool(host=REDIS_ADDR, port=REDIS_PORT, db=REDIS_TASK, decode_responses=True)
redis_task = redis.Redis(connection_pool=redis_pool2)
发表回复