Skip to content

Commit

Permalink
Merge pull request #2548 from sav-norem/patch-3
Browse files Browse the repository at this point in the history
Update hyperloglogs.md with hugo short codes
  • Loading branch information
dmaier-redislabs authored Oct 6, 2023
2 parents 4c318ff + 93e8a50 commit 970297c
Showing 1 changed file with 15 additions and 25 deletions.
40 changes: 15 additions & 25 deletions docs/data-types/probabilistic/hyperloglogs.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
---
title: "HyperLogLog"
linkTitle: "HyperLogLog"
weight: 1
Expand Down Expand Up @@ -37,12 +37,20 @@ only contains a state that does not include actual elements, the API is the
same:

* Every time you see a new element, you add it to the count with `PFADD`.
* Every time you want to retrieve the current approximation of the unique elements *added* with `PFADD` so far, you use the `PFCOUNT`.
* When you want to retrieve the current approximation of unique elements added using the `PFADD` command, you can use the `PFCOUNT` command. If you need to merge two different HLLs, the `PFMERGE` command is available. Since HLLs provide approximate counts of unique elements, the result of the merge will give you an approximation of the number of unique elements across both source HLLs.

> pfadd hll a b c d
(integer) 1
> pfcount hll
(integer) 4
{{< clients-example hll_tutorial pfadd >}}
> PFADD bikes Hyperion Deimos Phoebe Quaoar
(integer) 1
> PFCOUNT bikes
(integer) 4
> PFADD commuter_bikes Salacia Mimas Quaoar
(integer) 1
> PFMERGE all_bikes bikes commuter_bikes
OK
> PFCOUNT all_bikes
(integer) 6
{{< /clients-example >}}

Some examples of use cases for this data structure is counting unique queries
performed by users in a search form every day, number of unique visitors to a web page and other similar cases.
Expand All @@ -68,25 +76,6 @@ Storing the IP address or any other kind of personal identifier is against the l

One HyperLogLog is created per page (video/song) per period, and every IP/identifier is added to it on every visit.


## Examples

* Add some items to the HyperLogLog:
```
> PFADD members 123
(integer) 1
> PFADD members 500
(integer) 1
> PFADD members 12
(integer) 1
```

* Estimate the number of members in the set:
```
> PFCOUNT members
(integer) 3
```

## Basic commands

* `PFADD` adds an item to a HyperLogLog.
Expand All @@ -108,3 +97,4 @@ The HyperLogLog can estimate the cardinality of sets with up to 18,446,744,073,7

* [Redis new data structure: the HyperLogLog](http://antirez.com/news/75) has a lot of details about the data structure and its implementation in Redis.
* [Redis HyperLogLog Explained](https://www.youtube.com/watch?v=MunL8nnwscQ) shows you how to use Redis HyperLogLog data structures to build a traffic heat map.

0 comments on commit 970297c

Please sign in to comment.