redis from 0 to master - three special types HyperLoglog


What is the base?

a {1,3,5,7,8,7} b {1, 3, 5, 7, 8} base (not repeated element) = 5, can accept errors!


The HyperLogLog data structure is updated in Reis 2.8.9! REDIS HYPERLOGLOG Base statistics algorithm! Advantages: The memory occupied is fixed, 2 ^ 64 different elements, only need to waste 12KB memory! If you want to compare from memory angles, HyperLoglog is preferred!

UV of the page (a person visiting a website multiple times, but still counting as a person!)

Traditional way, SET saves the user’s ID, then you can count the number of elements in the set as a standard judgment!

This method will be more troublesome if you save a lot of user ID! Our purpose is to count, not to save user ID; 0.81% error rate! Statistics UV tasks can be ignored!

Test use> PFadd mykey a b c d e f g h i j # Create the first set of elements mykeyinteger) 1> PFCOUNT mykey # Statistics MyKeyThe number of bases (integer) 10> PFadd mykey2 i j z x c v b n m # Create a second set of elements mykey2 (integer) 1> PFCOUNT mykey2
(integer) 9> PFMERGE mykey3 mykey mykey2 # Merge two groups mykey mykey2 => myKey3Parallel OK127.0.0.1:6379> PFCOUNT mykey3 # Continue the number of considers! (integer) 15

If you are allowed tolerant, you can use HyperLoglog! If you do not allow fault tolerant, use SET or your own data type!