Redis Command-hyperloglog

Source: Internet
Author: User

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

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

  
 
  1. 127.0 0.1 : 6379 > Pfadd databases redis mongodb mysql
  2. ( integer ) Span class= "lit" style= "Color:rgb (25,95,145)" >1
  3. 127.0 0.1 : 6379 > Pfcount databases
  4. ( integer ) Span class= "lit" style= "Color:rgb (25,95,145)" >3
  5. 127.0 0.1 : 6379 > Pfadd databases redis
  6. ( integer ) Span class= "lit" style= "Color:rgb (25,95,145)" >0
  7. 127.0 0.1 : 6379 > Pfadd databases redistest
  8. ( integer ) Span class= "lit" style= "Color:rgb (25,95,145)" >1
  9. 127.0 0.1 : 6379 > Pfcount databases
  10. (integer) 4
    • Pfcount

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

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.

  
 
  1. 127.0 0.1 : 6379 > Pfadd NoSQL redis mongodb memcache
  2. ( integer ) Span class= "lit" style= "Color:rgb (25,95,145)" >1
  3. 127.0 0.1 : 6379 > Pfadd RDBMS MySQL MSSQL oracle
  4. (integer) 1

  1. 127.0 0.1 : 6379 > Pfmerge databases NoSQL RDBMS
  2. ok
  3. 127.0 0.1 : 6379 > Pfcount databases
  4. (integer) 9

Redis Command-hyperloglog

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.