Redis Bitmap 学习和使用
Redis Bitmap 学习和使用
Redis Bitmap介绍及应用
业务场景中如何巧妙的应用bitmap和zset
Set Bit
r = redis.Redis()
r.setbit("users-subscribed", 7, 0)
Get Bit
result = r.getbit("users-subscribed", 7)
print(result) # 0
result2 = r.get("users-subscribed")
print(result2) # 0
Bit Position
result = r.bitpos("users-subscribed", 1)
print(result) # 7
Bit Operation
r.setbit("users-subscribed-2", 6, 1)
result = r.bitop("AND", "newkey", "users-subscribed", "users-subscribed-2")
print(result) # 7
result2 = r.get("newkey")
print(result2) # 7
Bit Field
result = r.bitfield("bit-map", "incrby", "i5", 100, 4, "get", u4, 2)
print(result) # 7
Bit Count
result = r.bitcount("users-subscribed")
print(result) # 7
result2 = r.bitcount("users-subscribed", 0, 4)
print(result2) # 7