Redis HyperLogLog
Redis HYPERLOGLOG Command
Redis HyperLogLog is a algorithm that use randomization in order to provide an approximation of the number of unique elements in a set using just a constant, and small, amount of memory.
HyperLogLog provides a very good approximation of the cardinality of a set even using a very small amount of memory around 12 kbytes per key with a standard error of 0.81% and there is no limit to the number of items you can count, unless you approach 264 items.
Example:
Following example explains how redis HyperLogLog works:
redis 127.0.0.1:6379> PFADD tutorials "redis" 1) (integer) 1 redis 127.0.0.1:6379> PFADD tutorials "mongodb" 1) (integer) 1 redis 127.0.0.1:6379> PFADD tutorials "mysql" 1) (integer) 1 redis 127.0.0.1:6379> PFCOUNT tutorials (integer) 3
Redis HyperLogLog commands
Below given table shows some basic commands related to redis HyperLogLog:
Commands | Description |
---|---|
PFADD key element [element ...] | Adds the specified elements to the specified HyperLogLog. |
PFCOUNT key [key ...] | Return the approximated cardinality of the set(s) observed by the HyperLogLog at key(s). |
PFMERGE destkey sourcekey [sourcekey ...] | Merge N different HyperLogLogs into a single one. |