永远小于16kb
,内存占用低
的令人发指!作为代价,其测量结果是概率性的,有小于0.81%的误差
。不过对于UV统计来说,这完全可以忽略。PFADD key element [element...]
summary: Adds the specified elements to the specified HyperLogLog
PFCOUNT key [key ...]
Return the approximated cardinality of the set(s) observed by the HyperLogLog at key(s).
PFMERGE destkey sourcekey [sourcekey ...]
lnternal commands for debugging HyperLogLog values
使用单元测试,向HyperLogLog中添加100万条数据,看看内存占用是否真的那么低,以及统计误差如何
@Test
public void testHyperLogLog() {
String[] users = new String[1000];
int j = 0;
for (int i = 0; i < 1000000; i++) {
j = i % 1000;
users[j] = "user_" + i;
if (j == 999) {
stringRedisTemplate.opsForHyperLogLog().add("HLL", users);
}
}
Long count = stringRedisTemplate.opsForHyperLogLog().size("HLL");
System.out.println("count = " + count);
}