import redis标签:name,python,age,redis,hash1,print,链接,con From: https://www.cnblogs.com/longwanghzx/p/16600248.html
# 链接redis host,port,db
# 建立链接
con = redis.StrictRedis(
host='127.0.0.1',
port=6379,
db=4, # 默认使用的是0号
decode_responses=True
)
# string类型
# con.set('name','chuan')
# name = con.get('name')
# print(name)
# con.mset({'age':18,'sex':'boy'})
# re = con.mget('name','age','sex')
# print(re)
# list 类型
# con.lpush('list1','aa','bb','cc')
# con.lpop('list')
# result = con.lrange('list',0,-1)
# print(result)
# hash 类型
# con.hset('hash1','name','chuan')
# print(con.hget('hash1','name'))
# con.hmset('hash1',{'age':19,'addr':'changsha'})
print(con.hmget('hash1','name'))
# set 类型
con.sadd('set1','一','二')
print(con.smembers('set1'))
# zset 类型
con.zadd('zset1',{"aa":20,"bb":30})
print(con.zrange('zset1',0,-1))