From 783763b8f05ec427acdcf5a365f5410b04ee87a4 Mon Sep 17 00:00:00 2001 From: Savannah Date: Wed, 20 Sep 2023 11:25:54 -0400 Subject: [PATCH 1/3] Update hyperloglogs.md with hugo short codes added a pfmerge example - condensed to one more robust example --- docs/data-types/probabilistic/hyperloglogs.md | 42 ++++++++----------- 1 file changed, 17 insertions(+), 25 deletions(-) diff --git a/docs/data-types/probabilistic/hyperloglogs.md b/docs/data-types/probabilistic/hyperloglogs.md index 1f00455e74..e78f1dd47a 100644 --- a/docs/data-types/probabilistic/hyperloglogs.md +++ b/docs/data-types/probabilistic/hyperloglogs.md @@ -1,4 +1,4 @@ ---- +--- title: "HyperLogLog" linkTitle: "HyperLogLog" weight: 1 @@ -37,12 +37,22 @@ 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`. +* Every time you want to retrieve the current approximation of the unique elements *added* with `PFADD` so far, you use the `PFCOUNT`. Two different HLLs can be merged into a single one using `PFMERGE` and since HLLs approximate unique elements, the result of the merge is the approximated number of unique elements in the union of the source HLLs. + +{{< clients-example hll_tutorial pfadd >}} - > 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. @@ -68,25 +78,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. @@ -108,3 +99,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. + From f7c7152a29a6e84ea33b5ca3e2a8dc475adc9b0e Mon Sep 17 00:00:00 2001 From: Savannah Date: Mon, 2 Oct 2023 09:08:51 -0400 Subject: [PATCH 2/3] Update docs/data-types/probabilistic/hyperloglogs.md address feedback on PR Co-authored-by: David Dougherty --- docs/data-types/probabilistic/hyperloglogs.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/data-types/probabilistic/hyperloglogs.md b/docs/data-types/probabilistic/hyperloglogs.md index e78f1dd47a..7e2b6b241c 100644 --- a/docs/data-types/probabilistic/hyperloglogs.md +++ b/docs/data-types/probabilistic/hyperloglogs.md @@ -37,7 +37,7 @@ 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`. Two different HLLs can be merged into a single one using `PFMERGE` and since HLLs approximate unique elements, the result of the merge is the approximated number of unique elements in the union of the source HLLs. +* 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. {{< clients-example hll_tutorial pfadd >}} From 93e8a50552ccf3e35d83eb0a5415c1c6c1eed366 Mon Sep 17 00:00:00 2001 From: Savannah Date: Mon, 2 Oct 2023 09:40:15 -0400 Subject: [PATCH 3/3] remove superfluous short code --- docs/data-types/probabilistic/hyperloglogs.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/docs/data-types/probabilistic/hyperloglogs.md b/docs/data-types/probabilistic/hyperloglogs.md index 7e2b6b241c..89bbd11a38 100644 --- a/docs/data-types/probabilistic/hyperloglogs.md +++ b/docs/data-types/probabilistic/hyperloglogs.md @@ -39,8 +39,6 @@ same: * Every time you see a new element, you add it to the count with `PFADD`. * 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. -{{< clients-example hll_tutorial pfadd >}} - {{< clients-example hll_tutorial pfadd >}} > PFADD bikes Hyperion Deimos Phoebe Quaoar (integer) 1