redis hash operation

#-*- 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'] 
for hash in a key exists or notprint (r.hexists ( "xxx",
# determine whether there is a key
Print (r.hlen ( "xxx"))


# Length

  

 

Guess you like

Origin www.cnblogs.com/eliwen/p/11997338.html