Skip to content

Commit 8e5e239

Browse files
authored
Merge pull request phpredis#1656 from rlunar/HyperLogLogs
Hyper log logs
2 parents 8739fa5 + 9686757 commit 8e5e239

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed

README.markdown

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ If you've found phpredis useful and would like to buy the maintainers a coffee (
3333
* [Lists](#lists)
3434
* [Sets](#sets)
3535
* [Sorted sets](#sorted-sets)
36+
* [HyperLogLogs](#hyperloglogs)
3637
* [Geocoding](#geocoding)
3738
* [Streams](#streams)
3839
* [Pub/sub](#pubsub)
@@ -3114,6 +3115,86 @@ while($arr_matches = $redis->zScan('zset', $it, '*pattern*')) {
31143115
}
31153116
~~~
31163117

3118+
## HyperLogLogs
3119+
3120+
### pfAdd
3121+
-----
3122+
3123+
_**Description**_: Adds the specified elements to the specified HyperLogLog.
3124+
3125+
##### *Prototype*
3126+
~~~php
3127+
$redis->pfAdd($key, Array $elements);
3128+
~~~
3129+
3130+
##### *Parameters*
3131+
_Key_
3132+
_Array of values_
3133+
3134+
##### *Return value*
3135+
*Integer*: 1 if at least 1 HyperLogLog internal register was altered. 0 otherwise.
3136+
3137+
##### *Example*
3138+
~~~php
3139+
$redis->pfAdd('hll', ['a', 'b', 'c']); // (int) 1
3140+
$redis->pfAdd('hll', ['a', 'b']); // (int) 0
3141+
~~~
3142+
3143+
### pfCount
3144+
-----
3145+
3146+
_**Description**_: Return the approximated cardinality of the set(s) observed by the HyperLogLog at key(s).
3147+
3148+
##### *Prototype*
3149+
~~~php
3150+
$redis->pfCount($key);
3151+
$redis->pfCount(Array $keys);
3152+
~~~
3153+
3154+
##### *Parameters*
3155+
_Key_ or _Array of keys_
3156+
3157+
##### *Return value*
3158+
*Integer*: The approximated number of unique elements observed via [pfAdd](#pfAdd).
3159+
3160+
##### *Example*
3161+
~~~php
3162+
$redis->pfAdd('hll1', ['a', 'b', 'c']); // (int) 1
3163+
$redis->pfCount('hll1'); // (int) 3
3164+
3165+
$redis->pfAdd('hll2', ['d', 'e', 'a']); // (int) 1
3166+
$redis->pfCount('hll2'); // (int) 3
3167+
3168+
$redis->pfCount(['hll1', 'hll2']); // (int) 5
3169+
~~~
3170+
3171+
### pfMerge
3172+
-----
3173+
3174+
_**Description**_: Merge N different HyperLogLogs into a single one.
3175+
3176+
##### *Prototype*
3177+
~~~php
3178+
$redis->pfMerge($destkey, Array $sourceKeys);
3179+
~~~
3180+
3181+
##### *Parameters*
3182+
_Destination Key_
3183+
_Array of Source Keys_
3184+
3185+
##### *Return value*
3186+
*BOOL*: `TRUE` on success, `FALSE` on error.
3187+
3188+
##### *Example*
3189+
~~~php
3190+
$redis->pfAdd('hll1', ['a', 'b', 'c']); // (int) 1
3191+
$redis->pfAdd('hll2', ['d', 'e', 'a']); // (int) 1
3192+
3193+
$redis->pfMerge('hll3', ['hll1', 'hll2']); // true
3194+
3195+
$redis->pfCount('hll3'); // (int) 5
3196+
~~~
3197+
31173198
## Geocoding
31183199

31193200
### geoAdd

0 commit comments

Comments
 (0)