redis HyperLogLog use

First, the concept
1, redis in the 2.8.9 release adds HyperLogLog structure.
2, redis HyperLogLog radix is used for statistical algorithm, HyperLogLog advantage is that: when the input volume or the number of elements is very large, the space required for the calculation is always fixed base, and the very small.
3, in which redis, each key only takes HyperLogLog 12kb memory, can be calculated nearly 2 ^ 64 different base elements. When this calculation and the base, the more the cost of memory elements of the set, the more contrast.
4, however, because only HyperLogLog base calculated according to the input element, without storing the input element itself, it is not like HyperLogLog set as respective return input elements.

What is the cardinality
such data set {1,3,5,7,5,7,8}, the cardinality of the data set {1,3,5,7,8}, the base (not repeat elements) 5 . cardinality estimate error is within the acceptable range, fast calculation base.

Two, HyperLogLog related commands

  • Command name: pfadd
  • Syntax: pfadd key element [element ......]
  • Features:
    • Add any number of elements to the specified HyperLogLog inside.
    • As a side effect of this command, the internal HyperLogLog may be updated to reflect the estimated number of unique elements in a different (that is, cardinality of the set).
  • return value:
    • Integer reply: If the internal storage HyperLogLog is modified, it returns 1, otherwise it returns 0.

 

  • Command name: pfcount
  • Syntax: pfcount key [key ......]
  • Features:
    • When acting as pfcount command keys, return to the reservoir at approximately the base HyperLogLog given key, if the key does not exist, 0 is returned.
    • When pfcount command acts on a plurality of keys, return all the given set of approximate HyperLogLog and base, the base is approximately given by all combined to a temporary HyperLogLog HyperLogLog be calculated.
  • return value:
    • Integer Reply: approximate number of unique elements comprising HyperLogLog given.

 

  • Command name: pfmerge
  • 语法:pfmerge destkey sourcekey [sourcekey……]
  • Features:
    • The combined plurality HyperLogLog (Merge) is a HyperLogLog, HyperLogLog close to the base of the combined set of all visible HyperLogLog the input (observed set) and set.
  • return value:
    • Returns OK

Guess you like

Origin www.cnblogs.com/lxhyty/p/11511449.html