🔴 Redis Intermediate

What is HyperLogLog in Redis?

Answer

HyperLogLog is a probabilistic data structure in Redis that estimates the cardinality (number of unique elements) of a set with very low memory usage — approximately 12KB per HyperLogLog, regardless of the number of unique elements counted. PFADD key element [element ...] adds elements; PFCOUNT key [key ...] returns the estimated unique count. The error rate is approximately 0.81%. This is ideal for counting unique page views, unique visitors, or unique searches at massive scale where storing every individual user ID in a Set would consume enormous memory. For example, counting unique daily visitors across millions of users uses 12KB instead of potentially gigabytes. PFMERGE merges multiple HyperLogLogs, enabling counting unique visitors across date ranges.