每次打开连接会影响效率,本着省一点事一点的原则,应用连接池操作redis
安装redis库
pip install redis
from redispool import redis_pool,makeredisconn
def test():
redisconn = makeredisconn()
redisconn.set(username+"pc",token)
以上为项目代码和redis相关的,例如存储为start.py
import redis
redis_pool = redis.ConnectionPool(host='127.0.0.1', port=6379, db=0)
def makeredisconn():
conn = redis.Redis(connection_pool=redis_pool)
return conn
以上为redis连接池代码,存储为redispool.py