1.首先安装模块
pip3 install redis
2.代码模板如下:
from redis import StrictRedis
if __name__ == '__main__':
# 设置连接属性
sr = StrictRedis(host='192.168.8.102', port=7001,db=1)
sr_info = sr.info()
for key, val in sr_info.items():
print(key + ":", val)
sr.set("sex","man")
# 连接池
import redis
def con_redis():
pool = redis.ConnectionPool(host='192.168.8.102',
port=6379,
db=1,
)
r = redis.Redis(connection_pool=pool)
return r