redis : HyperLogLog

Redis added the HyperLogLog structure in version 2.8.9.

HyperLogLog is an algorithm for base statistics. The advantage of HyperLogLog is that when the number or volume of input elements is very large, the space required to calculate the base is always fixed and small.

In Redis, each HyperLogLog key only needs 12 KB of memory to calculate the base of close to 2^64 different elements. This is in sharp contrast to a collection where more elements consume more memory when calculating cardinality.

However, because HyperLogLog only calculates the cardinality based on the input element, and does not store the input element itself, HyperLogLog cannot return the input elements like a collection .

What is the base?

For example, the data set {1, 3, 5, 7, 5, 7, 8}, then the cardinality set of this data set is {1, 3, 5 ,7, 8}, and the cardinality (not repeating elements) is 5. Cardinality estimation is to quickly calculate the cardinality within the acceptable range of error.

The Pfadd command adds all element parameters to the HyperLogLog data structure.

The Pfcount command returns the estimated cardinality of a given HyperLogLog.

The PFMERGE command merges multiple HyperLogLogs into one HyperLogLog. The cardinality estimate of the merged HyperLogLog is calculated by the union of all given HyperLogLogs.

Guess you like

Origin blog.csdn.net/weixin_40179091/article/details/114892470