Jedis bitmap

位图

set bit key offset value  #给位图指定索引设置值 
setbit unique:users:2016-04-05 0 1  
0 
setbit unique:users:2016-01-05 5  1  
0 
setbit hello 7  
1
setbit hello 7 1 
0
get hello 
cig 

getbit

getbit key offset 
#获取位图指定索引的值  
getbit unique :users:2016-04-05 8  
integer 0 
getbit unique:users:2016-04-05 19 
1 

bitcount

bitcount key[start end]
#获取位图指定范围 start到end ,单位为字节,如果不指定就是获取全部位置为1个个数 
 bitcount unique:users:2016-04-05 
 interger 5 

bitop

bitop op destkey key[key]
做多个bitmap的and  or  not  xor 操作并将结果存放在destkey中 
#求两个位图的并集  

bitpos

bitpos key targetBt
计算位图指定范围,start到end,单位为字节,如果不指定就是获取全部 第一个偏移量对应的值等于targetBit的位置

bitpos unique:users:2016-04-04 1  
1 
bitpos unique:users:2016-04-04 0 1 2  
8

独立用户统计

1:使用set和bitmap
2:1亿用户,5千万独立

数据类型 每个发userid占用空间 需要存储的用户量 全部内存量
set 32位 50,000,000 32位*50,000,000= 200M
set 32位 100,000,000 1位*100,000,000 = 12.5M

使用经验

1:type=string ,最大512M
2:注意setbit时的偏移量 ,可能有较大好事

猜你喜欢

转载自blog.csdn.net/PYouLing123456789/article/details/83933201