11from redis .client import NEVER_DECODE
22from redis .exceptions import ModuleError
3- from redis .utils import HIREDIS_AVAILABLE
3+ from redis .utils import HIREDIS_AVAILABLE , deprecated_function
44
55BF_RESERVE = "BF.RESERVE"
66BF_ADD = "BF.ADD"
4949TDIGEST_MIN = "TDIGEST.MIN"
5050TDIGEST_MAX = "TDIGEST.MAX"
5151TDIGEST_INFO = "TDIGEST.INFO"
52+ TDIGEST_TRIMMED_MEAN = "TDIGEST.TRIMMED_MEAN"
53+ TDIGEST_RANK = "TDIGEST.RANK"
54+ TDIGEST_REVRANK = "TDIGEST.REVRANK"
55+ TDIGEST_BYRANK = "TDIGEST.BYRANK"
56+ TDIGEST_BYREVRANK = "TDIGEST.BYREVRANK"
5257
5358
5459class BFCommands :
@@ -67,6 +72,8 @@ def create(self, key, errorRate, capacity, expansion=None, noScale=None):
6772 self .append_no_scale (params , noScale )
6873 return self .execute_command (BF_RESERVE , * params )
6974
75+ reserve = create
76+
7077 def add (self , key , item ):
7178 """
7279 Add to a Bloom Filter `key` an `item`.
@@ -176,6 +183,8 @@ def create(
176183 self .append_max_iterations (params , max_iterations )
177184 return self .execute_command (CF_RESERVE , * params )
178185
186+ reserve = create
187+
179188 def add (self , key , item ):
180189 """
181190 Add an `item` to a Cuckoo Filter `key`.
@@ -316,6 +325,7 @@ def query(self, key, *items):
316325 """ # noqa
317326 return self .execute_command (TOPK_QUERY , key , * items )
318327
328+ @deprecated_function (version = "4.4.0" , reason = "deprecated since redisbloom 2.4.0" )
319329 def count (self , key , * items ):
320330 """
321331 Return count for one `item` or more from `key`.
@@ -344,12 +354,12 @@ def info(self, key):
344354
345355
346356class TDigestCommands :
347- def create (self , key , compression ):
357+ def create (self , key , compression = 100 ):
348358 """
349359 Allocate the memory and initialize the t-digest.
350360 For more information see `TDIGEST.CREATE <https://redis.io/commands/tdigest.create>`_.
351361 """ # noqa
352- return self .execute_command (TDIGEST_CREATE , key , compression )
362+ return self .execute_command (TDIGEST_CREATE , key , "COMPRESSION" , compression )
353363
354364 def reset (self , key ):
355365 """
@@ -358,26 +368,30 @@ def reset(self, key):
358368 """ # noqa
359369 return self .execute_command (TDIGEST_RESET , key )
360370
361- def add (self , key , values , weights ):
371+ def add (self , key , values ):
362372 """
363- Add one or more samples (value with weight) to a sketch `key`.
364- Both `values` and `weights` are lists.
365- For more information see `TDIGEST.ADD <https://redis.io/commands/tdigest.add>`_.
373+ Adds one or more observations to a t-digest sketch `key`.
366374
367- Example:
368-
369- >>> tdigestadd('A', [1500.0], [1.0])
375+ For more information see `TDIGEST.ADD <https://redis.io/commands/tdigest.add>`_.
370376 """ # noqa
371- params = [key ]
372- self .append_values_and_weights (params , values , weights )
373- return self .execute_command (TDIGEST_ADD , * params )
377+ return self .execute_command (TDIGEST_ADD , key , * values )
374378
375- def merge (self , toKey , fromKey ):
379+ def merge (self , destination_key , num_keys , * keys , compression = None , override = False ):
376380 """
377- Merge all of the values from 'fromKey' to 'toKey' sketch.
381+ Merges all of the values from `keys` to 'destination-key' sketch.
382+ It is mandatory to provide the `num_keys` before passing the input keys and
383+ the other (optional) arguments.
384+ If `destination_key` already exists its values are merged with the input keys.
385+ If you wish to override the destination key contents use the `OVERRIDE` parameter.
386+
378387 For more information see `TDIGEST.MERGE <https://redis.io/commands/tdigest.merge>`_.
379388 """ # noqa
380- return self .execute_command (TDIGEST_MERGE , toKey , fromKey )
389+ params = [destination_key , num_keys , * keys ]
390+ if compression is not None :
391+ params .extend (["COMPRESSION" , compression ])
392+ if override :
393+ params .append ("OVERRIDE" )
394+ return self .execute_command (TDIGEST_MERGE , * params )
381395
382396 def min (self , key ):
383397 """
@@ -393,20 +407,21 @@ def max(self, key):
393407 """ # noqa
394408 return self .execute_command (TDIGEST_MAX , key )
395409
396- def quantile (self , key , quantile ):
410+ def quantile (self , key , quantile , * quantiles ):
397411 """
398- Return double value estimate of the cutoff such that a specified fraction of the data
399- added to this TDigest would be less than or equal to the cutoff.
412+ Returns estimates of one or more cutoffs such that a specified fraction of the
413+ observations added to this t-digest would be less than or equal to each of the
414+ specified cutoffs. (Multiple quantiles can be returned with one call)
400415 For more information see `TDIGEST.QUANTILE <https://redis.io/commands/tdigest.quantile>`_.
401416 """ # noqa
402- return self .execute_command (TDIGEST_QUANTILE , key , quantile )
417+ return self .execute_command (TDIGEST_QUANTILE , key , quantile , * quantiles )
403418
404- def cdf (self , key , value ):
419+ def cdf (self , key , value , * values ):
405420 """
406421 Return double fraction of all points added which are <= value.
407422 For more information see `TDIGEST.CDF <https://redis.io/commands/tdigest.cdf>`_.
408423 """ # noqa
409- return self .execute_command (TDIGEST_CDF , key , value )
424+ return self .execute_command (TDIGEST_CDF , key , value , * values )
410425
411426 def info (self , key ):
412427 """
@@ -416,6 +431,50 @@ def info(self, key):
416431 """ # noqa
417432 return self .execute_command (TDIGEST_INFO , key )
418433
434+ def trimmed_mean (self , key , low_cut_quantile , high_cut_quantile ):
435+ """
436+ Return mean value from the sketch, excluding observation values outside
437+ the low and high cutoff quantiles.
438+ For more information see `TDIGEST.TRIMMED_MEAN <https://redis.io/commands/tdigest.trimmed_mean>`_.
439+ """ # noqa
440+ return self .execute_command (
441+ TDIGEST_TRIMMED_MEAN , key , low_cut_quantile , high_cut_quantile
442+ )
443+
444+ def rank (self , key , value , * values ):
445+ """
446+ Retrieve the estimated rank of value (the number of observations in the sketch
447+ that are smaller than value + half the number of observations that are equal to value).
448+
449+ For more information see `TDIGEST.RANK <https://redis.io/commands/tdigest.rank>`_.
450+ """ # noqa
451+ return self .execute_command (TDIGEST_RANK , key , value , * values )
452+
453+ def revrank (self , key , value , * values ):
454+ """
455+ Retrieve the estimated rank of value (the number of observations in the sketch
456+ that are larger than value + half the number of observations that are equal to value).
457+
458+ For more information see `TDIGEST.REVRANK <https://redis.io/commands/tdigest.revrank>`_.
459+ """ # noqa
460+ return self .execute_command (TDIGEST_REVRANK , key , value , * values )
461+
462+ def byrank (self , key , rank , * ranks ):
463+ """
464+ Retrieve an estimation of the value with the given rank.
465+
466+ For more information see `TDIGEST.BY_RANK <https://redis.io/commands/tdigest.by_rank>`_.
467+ """ # noqa
468+ return self .execute_command (TDIGEST_BYRANK , key , rank , * ranks )
469+
470+ def byrevrank (self , key , rank , * ranks ):
471+ """
472+ Retrieve an estimation of the value with the given reverse rank.
473+
474+ For more information see `TDIGEST.BY_REVRANK <https://redis.io/commands/tdigest.by_revrank>`_.
475+ """ # noqa
476+ return self .execute_command (TDIGEST_BYREVRANK , key , rank , * ranks )
477+
419478
420479class CMSCommands :
421480 """Count-Min Sketch Commands"""
0 commit comments