Redis Foundation of HYPERLOGLOG data structure __ data structure

Source: Internet
Author: User
Tags redis
First, overview:

Redis added a hyperloglog structure in version 2.8.9.

Redishyperloglog is the algorithm used to do cardinality statistics, the advantage of Hyperloglog is that when the number or volume of input elements is very large, the space required to compute the cardinality is always fixed, and is very small.

In Redis, each Hyperloglog key takes only a few kilobytes of memory to compute the cardinality of nearly 2^64 different elements. This is in stark contrast to the number of elements that consume more memory as the base is computed.

However, because Hyperloglog only calculates the cardinality based on the input elements and does not store the INPUT element itself, Hyperloglog cannot return the elements of the input as a collection.

second, what is the base?

For example DataSet {1, 3, 5, 7, 5, 7, 8}, then the cardinality set for this dataset is {1, 3, 5, 7, 8}, and cardinality (not repeating element) is 5. The cardinality estimate is the rapid calculation of the cardinality within an acceptable range of errors.

third, the related command list:

Command Prototypes

Complexity of Time

Command Description

return value

Pfadd key element [element ...]

O (1)

Adds the specified element to the Hyperloglog.

Returns 0 if at least 1 hyperloglog send the change.

Pfcount key [Key ...]

O (1)-O (N)

Returns the cardinality estimate for the given Hyperloglog.

Returns the approximate number of unique elements added through Pfadd.

Pfmerge destkey Sourcekey [Sourcekey ...]

O (1)

Merges multiple hyperloglog into one hyperloglog.

return OK.

iv. Examples of commands:

Redis> Pfadd HLL a b c d E F g

(integer) 1

Redis> Pfcount HLL

(integer) 7

redis> pfadd hll foo bar Zap

(integer) 1

Redis> Pfadd hll Zap Zap Zap

(integer) 0

redis> pfadd hll foo Bar

(integer) 0

Redis> Pfcount HLL

(integer) 3

Redis> pfadd SOME-OTHER-HLL 1 2 3

(integer) 1

redis> Pfcount HLL Some-other-hll

(integer) 6

redis> pfadd hll1 Foo bar zap A

(integer) 1

Redis> Pfadd hll2 a b c foo

(integer) 1

redis> pfmerge hll3 hll1 hll2

Ok

Redis> Pfcount Hll3

(integer) 6

Redis>

v. Scope of application:

An example of this data structure is the unique number of queries that the user makes each day in a search form.

Six, command operation

Visit the website: http://try.redis.io/, and then make the command operation;

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.