Bitmap类型详解

Bitmap类型详解

使用场景:用bitmap来记录周一到周日的打卡

添加和获取

# setbit 设置值
# getbit 获取值
127.0.0.1:6379[3]> setbit sign 0 0
(integer) 0
127.0.0.1:6379[3]> setbit sign 1 1
(integer) 0
127.0.0.1:6379[3]> setbit sign 2 0
(integer) 0
127.0.0.1:6379[3]> setbit sign 3 1
(integer) 0
127.0.0.1:6379[3]> setbit sign 4 1
(integer) 0
127.0.0.1:6379[3]> setbit sign 5 0
(integer) 0
127.0.0.1:6379[3]> setbit sign 6 0
(integer) 0
127.0.0.1:6379[3]> getbit sign 5
(integer) 0
127.0.0.1:6379[3]> getbit sign 4
(integer) 1
127.0.0.1:6379[3]> setbit sign 7 2 # 位图的存储值只能为0或1,不能为2,-1
(error) ERR bit is not an integer or out of range
127.0.0.1:6379[3]> setbit sign 7 -1
(error) ERR bit is not an integer or out of range

统计

# bitcount 统计打卡数量
127.0.0.1:6379[3]> bitcount sign 0 -1
(integer) 3
posted @ 2022-02-25 16:49  Oh,mydream!  阅读(144)  评论(0编辑  收藏  举报