【十三】redis衍生数据结构之位图Bigmap

位图,redis可以操作二进制的位,可以取到每一个位对应的值。

node1:0>set hello big
"OK"

node1:0>getbit hello 0
"0"

node1:0>getbit hello 1
"1"

node1:0>getbit hello 2
"1"

node1:0>getbit hello 3
"0"

node1:0>getbit hello 4
"0"

node1:0>getbit hello 5
"0"

node1:0>getbit hello 6
"1"

node1:0>getbit hello 7
"0"

node1:0>

命令

setbit key offset value  给位图指定偏移设置值,偏移从0开始,值只能是0或1

原本hello的值是big

如果setbit hello 100 1 那么24-99都会自动补为0,不要给一个很短的bigmap设置很长位的偏移量的值,这样有可能堵塞

getbit key offset  获取位图指定偏移的值

bitcount key start end  获取位图指定范围内值为1的个数,不指定start end就默认全部

bitop op destkey key [key...]   做多个bitmap的and交集 or并集  not非  xor 异或,操作结果保存在destkey中

bitpos key targetBit [start] [end]  计算位图指定范围内(不指定start end默认全部)第一个偏移量对应的值等于targetBit的位置

猜你喜欢

转载自blog.csdn.net/jy02268879/article/details/81459208