#-*- coding: utf8 -*-

import redis



pool = redis.ConnectionPool()

r = redis.Redis(connection_pool=pool)

# 设置获取
r.hset("info", "name", "alex")
print(r.hget("info","name")) # b'alex'
print(r.hgetall("info"))         # {b'name': b'alex'}

# 批量操作 

r.hmset("xxx",{"k1":"v1","k2":"v2"})
print(r.hgetall("info"))             # {b'name': b'alex'}

r.hmset("xxx",{"k1":"v1","k2":"v2"})
print(r.hmget("xxx",["k1","k2"]))      #  [b'v1', b'v2']


# 长度
print(r.hlen("xxx"))

# 判断是否存在某个键 
print(r.hexists("xxx","k3"))    # 针对hash里某个键存不存在