Introduction
The HyperLogLog command family uses probabilistic algorithms to estimate the cardinality (count of distinct elements) of extremely large datasets. Each HyperLogLog key occupies a fixed memory footprint of approximately 12 KB, with a standard error of about 0.81%. These commands are suitable for scenarios that do not require exact values, such as UV (Unique Visitor) statistics, search keyword deduplication counting, and large-scale duplicate detection. They can replace Set storage for cardinality estimation at the scale of hundreds of millions, at a very low memory cost. Based on their features, the core commands can be categorized into the following three types:
Add elements
PFADD: Adds one or more elements to a HyperLogLog structure. Internally, it records element characteristics using hash buckets and probabilistic algorithms.
Cardinality Estimation
PFCOUNT: Returns the estimated cardinality for one or more HyperLogLog keys. It also supports directly calculating the union cardinality of multiple keys.
Merge Operations
PFMERGE: Merges multiple HyperLogLog keys into one, stores the union into a destination key, and is suitable for cross-time/cross-dimensional cardinality aggregation scenarios such as multi-day UV accumulation and multi-source deduplication.
Command Support Overview
Basic Commands: pfadd, pfcount, and pfmerge are fully supported in the standard architecture of Redis versions 2.8, 4.0, 5.0, 6.2, and 7.0, as well as in the standard and cluster architectures of Valkey versions 8.0 and 9.0.
Cross-Slot Restriction: In a cluster architecture, pfcount and pfmerge do not support cross-slot operations. pfadd does not involve cross-slot access scenarios.
Command Compatibility Matrix
The support status of HyperLogLog family commands across different versions and architectures is shown in the table below (✓ indicates supported, ✗ indicates not supported, and — indicates that the command does not involve a cross-slot access scenario).
|
pfadd | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | — |
pfcount | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✗ |
pfmerge | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✗ |