Hyperloglog是redis提供的一种类型,专门用来做基数统计,直白说就是统计一堆数据中有多少不重复的数据。
Hyperloglog的优点是占用空间小;缺点是有误差,大概为0.81%,但是在大数据面前可以忽略不计。
127.0.0.1:6379> pfadd set1 1 2 3 4 5 6 7 8 9//添加查询集
(integer) 1
127.0.0.1:6379> pfadd set2 7 8 9 10 11 12 13 14//再添加一个
(integer) 1
127.0.0.1:6379> pfcount set1//统计set1
(integer) 9//有9个不重复元素
127.0.0.1:6379> pfcount set2//统计set2
(integer) 8//有8个不重复元素
127.0.0.1:6379> pfmerge set3 set1 set2//合并set1和set2,结果放入set3
OK
127.0.0.1:6379> pfcount set3//统计set3
(integer) 14//有14个不重复元素



