Introduction to the Redis HyperLogLog data type
HyperLogLog is a data structure that estimates the cardinality of a set. As a probabilistic data structure, HyperLogLog trades perfect accuracy for efficient space utilization.
The Redis HyperLogLog implementation uses up to 12 KB and provides a standard error of 0.81%.
- Add some items to the HyperLogLog:
> PFADD members 123 (integer) 1 > PFADD members 500 (integer) 1 > PFADD members 12 (integer) 1
- Estimate the number of members in the set:
> PFCOUNT members (integer) 3
PFADDadds an item to a HyperLogLog.
PFCOUNTreturns an estimate of the number of items in the set.
PFMERGEcombines two or more HyperLogLogs into one.
See the complete list of HyperLogLog commands.
PFADD) to and reading from (
PFCOUNT) the HyperLogLog is done in constant time and space.
Merging HLLs is O(n), where n is the number of sketches.
The HyperLogLog can estimate the cardinality of sets with up to 18,446,744,073,709,551,616 (2^64) members.
- Redis new data structure: the HyperLogLog has a lot of details about the data structure and its implementation in Redis.
- Redis HyperLogLog Explained shows you how to use Redis HyperLogLog data structures to build a traffic heat map.