Hyperloglog Data Structure Introduction
can see Http://www.cnblogs.com/ysuzhaixuefei/p/4052110.html blog, the relative clarity of the introduction.
Hyperloglog data structures, you can receive multiple parameter inputs, and then estimate the cardinality of the element.
? Cardinality: The number of different elements in the collection. For example {' Apple ', ' banana ', ' cherry ', ' banana ', ' apple ' is the base of 3.
? Estimates: the cardinality given by the algorithm is not accurate, may be slightly more or less than the actual, but will control the
Within the scope of the rationale.
The advantage of Hyperloglog is that even if the number of input elements or the volume is very large, the space required to calculate the cardinality is always fixed
, and it's very small.
In Redis, each Hyperloglog key requires only a few kilobytes of memory to compute a base that is close to 2^64 different elements.
Number. This is in stark contrast to the larger set of elements that consume more memory when calculating the cardinality.
However, because Hyperloglog only calculates the cardinality based on the input element and does not store the INPUT element itself,
Hyperloglog cannot return individual elements of the input as a collection.
Pfadd key [element ...] : Add any number of elements to the specified hyperloglog. Relative updates the hyperloglog interior, changing the cardinality of the collection. Returns 1 if the cardinality of the corresponding Hyperloglog is changed, otherwise 0 is returned.
Return value: Cardinality is modified to return 1, otherwise 0 is returned
127.0 0.1 : 6379 > Pfadd databases redis mongodb mysql
( integer ) Span class= "lit" style= "Color:rgb (25,95,145)" >1
127.0 0.1 : 6379 > Pfcount databases
( integer ) Span class= "lit" style= "Color:rgb (25,95,145)" >3
127.0 0.1 : 6379 > Pfadd databases redis
( integer ) Span class= "lit" style= "Color:rgb (25,95,145)" >0
127.0 0.1 : 6379 > Pfadd databases redistest
( integer ) Span class= "lit" style= "Color:rgb (25,95,145)" >1
127.0 0.1 : 6379 > Pfcount databases
(integer) 4
Pfcount Key[key ...] : Pfcount returns the cardinality of a key when it is acting on a single key. When the Pfcount command acts on more than one key, the approximate number of the set is returned.
Return value: The cardinality of the given Hyperloglog.
Pfmerge destkey Sourcekey[sorcekey ...] : Merging multiple hyperloglog into one hyperloglog, the cardinality of the merged Hyperloglog is close to the union of all the visible sets of inputs. The merged hyperloglog will be stored in the Destkey.
Return value: OK returned successfully.
127.0 0.1 : 6379 > Pfadd NoSQL redis mongodb memcache
( integer ) Span class= "lit" style= "Color:rgb (25,95,145)" >1
127.0 0.1 : 6379 > Pfadd RDBMS MySQL MSSQL oracle
(integer) 1
127.0 0.1 : 6379 > Pfmerge databases NoSQL RDBMS
ok
127.0 0.1 : 6379 > Pfcount databases
(integer) 9
Redis Command-hyperloglog