首先安装redis的相关包:
pip install redis
连接redis:
RDSHOST = "10.10.10.10" #服务器地址
RDSPWD = "******" #密码
RDSDB = 14 #库
r = redis.Redis(host = RDSHOST,password = RDSPWD,db=RDSDB,port=6379)
#获取全部的key
value = r.keys()
#根据key获取value
value = r.get(key) #没有值返回空
#数据存储
r.set(key,value)
批量写:
lis = [{key1:value1},{key2:value2},{key3:value3}]
r.set(lis)
批量读:
lis = [key1,key2,key3]
value = r.mget(lis)