Redis中关于BitMap操作命令
BitMap是Redis2.2.0版本引入的一种数据类型。
命令:SETBIT key offset value
意思:对给定的key的指定的位置设置数值。其中数值value只能是0或者1
相关命令有:
setbit:SETBIT key offset value
offset在这里指的是员工的编号
value:1 表示上班,0表示未上班
127.0.0.1:6379> setbit shangban 1 1
(integer) 0
127.0.0.1:6379> setbit shangban 2 0
(integer) 0
getbit:GETBIT key offset
127.0.0.1:6379> getbit shangban 1
(integer) 1
bitcount::BITCOUNT key [start] [end]
指的是0号员工的上班次数
127.0.0.1:6379> bitcount shangban 0 1
(integer) 1
bitpos:BITPOS key bit [start] [end]
指的是上班签到的第一次所处的位置
127.0.0.1:6379> bitpos shangban 1
(integer) 1
bitop:BITOP operation destkey key
应用场景:
用于统计员工(上班,未上班)、支持率统计(支持,不支持),适合这种非此即彼的大数据的情况