
    +hS                     T   d dl mZ d dlmZ d dlmZmZ dZdZdZ	dZ
dZd	Zd
ZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZ dZ!dZ"d Z#d!Z$d"Z%d#Z&d$Z'd%Z(d&Z)d'Z*d(Z+d)Z,d*Z-d+Z.d,Z/d-Z0d.Z1d/Z2d0Z3d1Z4d2Z5d3Z6d4Z7 G d5 d6      Z8 G d7 d8      Z9 G d9 d:      Z: G d; d<      Z; G d= d>      Z<y?)@    )NEVER_DECODE)ModuleError)HIREDIS_AVAILABLEdeprecated_functionz
BF.RESERVEzBF.ADDzBF.MADDz	BF.INSERTz	BF.EXISTSz
BF.MEXISTSzBF.SCANDUMPzBF.LOADCHUNKzBF.INFOzBF.CARDz
CF.RESERVEzCF.ADDzCF.ADDNXz	CF.INSERTzCF.INSERTNXz	CF.EXISTSz
CF.MEXISTSzCF.DELzCF.COUNTzCF.SCANDUMPzCF.LOADCHUNKzCF.INFOzCMS.INITBYDIMzCMS.INITBYPROBz
CMS.INCRBYz	CMS.QUERYz	CMS.MERGEzCMS.INFOzTOPK.RESERVEzTOPK.ADDzTOPK.INCRBYz
TOPK.QUERYz
TOPK.COUNTz	TOPK.LISTz	TOPK.INFOzTDIGEST.CREATEzTDIGEST.RESETzTDIGEST.ADDzTDIGEST.MERGEzTDIGEST.CDFzTDIGEST.QUANTILEzTDIGEST.MINzTDIGEST.MAXzTDIGEST.INFOzTDIGEST.TRIMMED_MEANzTDIGEST.RANKzTDIGEST.REVRANKzTDIGEST.BYRANKzTDIGEST.BYREVRANKc                   ^    e Zd ZdZddZeZd Zd Z	 	 	 	 	 ddZd Z	d Z
d	 Zd
 Zd Zd Zy)
BFCommandszBloom Filter commands.Nc                     |||g}| j                  ||       | j                  ||        | j                  t        g| S )aA  
        Create a new Bloom Filter `key` with desired probability of false positives
        `errorRate` expected entries to be inserted as `capacity`.
        Default expansion value is 2. By default, filter is auto-scaling.
        For more information see `BF.RESERVE <https://redis.io/commands/bf.reserve>`_.
        )append_expansionappend_no_scaleexecute_command
BF_RESERVE)selfkey	errorRatecapacity	expansionnoScaleparamss          M/var/www/html/venv/lib/python3.12/site-packages/redis/commands/bf/commands.pycreatezBFCommands.create?   sH     y(+fi0VW-#t##J888    c                 0    | j                  t        ||      S )z
        Add to a Bloom Filter `key` an `item`.
        For more information see `BF.ADD <https://redis.io/commands/bf.add>`_.
        )r   BF_ADDr   r   items      r   addzBFCommands.addM       
 ##FC66r   c                 2     | j                   t        |g| S )z
        Add to a Bloom Filter `key` multiple `items`.
        For more information see `BF.MADD <https://redis.io/commands/bf.madd>`_.
        )r   BF_MADDr   r   itemss      r   maddzBFCommands.maddT   s    
 $t##GS9599r   c                    |g}| j                  ||       | j                  ||       | j                  ||       | j                  ||       | j	                  ||       | j                  ||        | j                  t        g| S )as  
        Add to a Bloom Filter `key` multiple `items`.

        If `nocreate` remain `None` and `key` does not exist, a new Bloom Filter
        `key` will be created with desired probability of false positives `errorRate`
        and expected entries to be inserted as `size`.
        For more information see `BF.INSERT <https://redis.io/commands/bf.insert>`_.
        )append_capacityappend_errorr
   append_no_creater   append_itemsr   	BF_INSERT)	r   r   r!   r   errornoCreater   r   r   s	            r   insertzBFCommands.insert[   s    $ VX.&%(fi0fh/VW-&%(#t##I777r   c                 0    | j                  t        ||      S )z
        Check whether an `item` exists in Bloom Filter `key`.
        For more information see `BF.EXISTS <https://redis.io/commands/bf.exists>`_.
        )r   	BF_EXISTSr   s      r   existszBFCommands.existsw       
 ##IsD99r   c                 2     | j                   t        |g| S )z
        Check whether `items` exist in Bloom Filter `key`.
        For more information see `BF.MEXISTS <https://redis.io/commands/bf.mexists>`_.
        )r   
BF_MEXISTSr    s      r   mexistszBFCommands.mexists~       
 $t##J<e<<r   c                 v    t         rt        d      ||g}i }g |t        <    | j                  t        g|i |S )a  
        Begin an incremental save of the bloom filter `key`.

        This is useful for large bloom filters which cannot fit into the normal SAVE and RESTORE model.
        The first time this command is called, the value of `iter` should be 0.
        This command will return successive (iter, data) pairs until (0, NULL) to indicate completion.
        For more information see `BF.SCANDUMP <https://redis.io/commands/bf.scandump>`_.
        z6This command cannot be used when hiredis is available.)r   r   r   r   BF_SCANDUMP)r   r   iterr   optionss        r   scandumpzBFCommands.scandump   sH     VWWt "#t##KD&DGDDr   c                 2    | j                  t        |||      S )ai  
        Restore a filter previously saved using SCANDUMP.

        See the SCANDUMP command for example usage.
        This command will overwrite any bloom filter stored under key.
        Ensure that the bloom filter will not be modified between invocations.
        For more information see `BF.LOADCHUNK <https://redis.io/commands/bf.loadchunk>`_.
        )r   BF_LOADCHUNKr   r   r6   datas       r   	loadchunkzBFCommands.loadchunk   s     ##L#tTBBr   c                 .    | j                  t        |      S )z
        Return capacity, size, number of filters, number of items inserted, and expansion rate.
        For more information see `BF.INFO <https://redis.io/commands/bf.info>`_.
        )r   BF_INFOr   r   s     r   infozBFCommands.info   s    
 ##GS11r   c                 .    | j                  t        |      S )a*  
        Returns the cardinality of a Bloom filter - number of items that were added to a Bloom filter and detected as unique
        (items that caused at least one bit to be set in at least one sub-filter).
        For more information see `BF.CARD <https://redis.io/commands/bf.card>`_.
        )r   BF_CARDr@   s     r   cardzBFCommands.card        ##GS11r   NN)NNNNN)__name__
__module____qualname____doc__r   reserver   r"   r+   r.   r2   r8   r=   rA   rD    r   r   r   r   <   sQ     
9 G7: 88:=E"	C22r   r   c                   d    e Zd ZdZ	 ddZeZd Zd ZddZddZ	d Z
d	 Zd
 Zd Zd Zd Zd Zy)
CFCommandszCuckoo Filter commands.Nc                     ||g}| j                  ||       | j                  ||       | j                  ||        | j                  t        g| S )z
        Create a new Cuckoo Filter `key` an initial `capacity` items.
        For more information see `CF.RESERVE <https://redis.io/commands/cf.reserve>`_.
        )r
   append_bucket_sizeappend_max_iterationsr   
CF_RESERVE)r   r   r   r   bucket_sizemax_iterationsr   s          r   r   zCFCommands.create   sU     xfi04""6>:#t##J888r   c                 0    | j                  t        ||      S )z
        Add an `item` to a Cuckoo Filter `key`.
        For more information see `CF.ADD <https://redis.io/commands/cf.add>`_.
        )r   CF_ADDr   s      r   r   zCFCommands.add   r   r   c                 0    | j                  t        ||      S )z
        Add an `item` to a Cuckoo Filter `key` only if item does not yet exist.
        Command might be slower that `add`.
        For more information see `CF.ADDNX <https://redis.io/commands/cf.addnx>`_.
        )r   CF_ADDNXr   s      r   addnxzCFCommands.addnx   s     ##Hc488r   c                     |g}| j                  ||       | j                  ||       | j                  ||        | j                  t        g| S )a  
        Add multiple `items` to a Cuckoo Filter `key`, allowing the filter
        to be created with a custom `capacity` if it does not yet exist.
        `items` must be provided as a list.
        For more information see `CF.INSERT <https://redis.io/commands/cf.insert>`_.
        )r$   r&   r'   r   	CF_INSERTr   r   r!   r   nocreater   s         r   r+   zCFCommands.insert   sS     VX.fh/&%(#t##I777r   c                     |g}| j                  ||       | j                  ||       | j                  ||        | j                  t        g| S )a@  
        Add multiple `items` to a Cuckoo Filter `key` only if they do not exist yet,
        allowing the filter to be created with a custom `capacity` if it does not yet exist.
        `items` must be provided as a list.
        For more information see `CF.INSERTNX <https://redis.io/commands/cf.insertnx>`_.
        )r$   r&   r'   r   CF_INSERTNXr\   s         r   insertnxzCFCommands.insertnx   sS     VX.fh/&%(#t##K9&99r   c                 0    | j                  t        ||      S )z
        Check whether an `item` exists in Cuckoo Filter `key`.
        For more information see `CF.EXISTS <https://redis.io/commands/cf.exists>`_.
        )r   	CF_EXISTSr   s      r   r.   zCFCommands.exists   r/   r   c                 2     | j                   t        |g| S )z
        Check whether an `items` exist in Cuckoo Filter `key`.
        For more information see `CF.MEXISTS <https://redis.io/commands/cf.mexists>`_.
        )r   
CF_MEXISTSr    s      r   r2   zCFCommands.mexists   r3   r   c                 0    | j                  t        ||      S )zz
        Delete `item` from `key`.
        For more information see `CF.DEL <https://redis.io/commands/cf.del>`_.
        )r   CF_DELr   s      r   deletezCFCommands.delete   r   r   c                 0    | j                  t        ||      S )z
        Return the number of times an `item` may be in the `key`.
        For more information see `CF.COUNT <https://redis.io/commands/cf.count>`_.
        )r   CF_COUNTr   s      r   countzCFCommands.count  s    
 ##Hc488r   c                 0    | j                  t        ||      S )a  
        Begin an incremental save of the Cuckoo filter `key`.

        This is useful for large Cuckoo filters which cannot fit into the normal
        SAVE and RESTORE model.
        The first time this command is called, the value of `iter` should be 0.
        This command will return successive (iter, data) pairs until
        (0, NULL) to indicate completion.
        For more information see `CF.SCANDUMP <https://redis.io/commands/cf.scandump>`_.
        )r   CF_SCANDUMP)r   r   r6   s      r   r8   zCFCommands.scandump  s     ##Kd;;r   c                 2    | j                  t        |||      S )ac  
        Restore a filter previously saved using SCANDUMP. See the SCANDUMP command for example usage.

        This command will overwrite any Cuckoo filter stored under key.
        Ensure that the Cuckoo filter will not be modified between invocations.
        For more information see `CF.LOADCHUNK <https://redis.io/commands/cf.loadchunk>`_.
        )r   CF_LOADCHUNKr;   s       r   r=   zCFCommands.loadchunk  s     ##L#tTBBr   c                 .    | j                  t        |      S )z
        Return size, number of buckets, number of filter, number of items inserted,
        number of items deleted, bucket size, expansion rate, and max iteration.
        For more information see `CF.INFO <https://redis.io/commands/cf.info>`_.
        )r   CF_INFOr@   s     r   rA   zCFCommands.info  rE   r   )NNNrF   )rG   rH   rI   rJ   r   rK   r   rY   r+   r`   r.   r2   rg   rj   r8   r=   rA   rL   r   r   rN   rN      sP    ! OS9 G798::=79<C2r   rN   c                   V    e Zd ZdZd Zd Zd Zd Z edd      d	        Z	dd
Z
d Zy)TOPKCommandszTOP-k Filter commands.c                 6    | j                  t        |||||      S )z
        Create a new Top-K Filter `key` with desired probability of false
        positives `errorRate` expected entries to be inserted as `size`.
        For more information see `TOPK.RESERVE <https://redis.io/commands/topk.reserve>`_.
        )r   TOPK_RESERVE)r   r   kwidthdepthdecays         r   rK   zTOPKCommands.reserve+  s     ##L#q%NNr   c                 2     | j                   t        |g| S )z
        Add one `item` or more to a Top-K Filter `key`.
        For more information see `TOPK.ADD <https://redis.io/commands/topk.add>`_.
        )r   TOPK_ADDr    s      r   r   zTOPKCommands.add3  s    
 $t##Hc:E::r   c                 \    |g}| j                  |||        | j                  t        g| S )a  
        Add/increase `items` to a Top-K Sketch `key` by ''increments''.
        Both `items` and `increments` are lists.
        For more information see `TOPK.INCRBY <https://redis.io/commands/topk.incrby>`_.

        Example:

        >>> topkincrby('A', ['foo'], [1])
        )append_items_and_incrementsr   TOPK_INCRBYr   r   r!   
incrementsr   s        r   incrbyzTOPKCommands.incrby:  s5     ((
C#t##K9&99r   c                 2     | j                   t        |g| S )z
        Check whether one `item` or more is a Top-K item at `key`.
        For more information see `TOPK.QUERY <https://redis.io/commands/topk.query>`_.
        )r   
TOPK_QUERYr    s      r   queryzTOPKCommands.queryH  r3   r   z4.4.0z!deprecated since redisbloom 2.4.0)versionreasonc                 2     | j                   t        |g| S )z
        Return count for one `item` or more from `key`.
        For more information see `TOPK.COUNT <https://redis.io/commands/topk.count>`_.
        )r   
TOPK_COUNTr    s      r   rj   zTOPKCommands.countO  s     $t##J<e<<r   c                 \    |g}|r|j                  d        | j                  t        g| S )a  
        Return full list of items in Top-K list of `key`.
        If `withcount` set to True, return full list of items
        with probabilistic count in Top-K list of `key`.
        For more information see `TOPK.LIST <https://redis.io/commands/topk.list>`_.
        	WITHCOUNT)appendr   	TOPK_LIST)r   r   	withcountr   s       r   listzTOPKCommands.listW  s2     MM+&#t##I777r   c                 .    | j                  t        |      S )z
        Return k, width, depth and decay values of `key`.
        For more information see `TOPK.INFO <https://redis.io/commands/topk.info>`_.
        )r   	TOPK_INFOr@   s     r   rA   zTOPKCommands.infoc  s    
 ##Is33r   N)F)rG   rH   rI   rJ   rK   r   r   r   r   rj   r   rA   rL   r   r   rr   rr   (  sA     O;:= 1TU= V=
84r   rr   c                   j    e Zd ZddZd Zd ZddddZd Zd	 Zd
 Z	d Z
d Zd Zd Zd Zd Zd Zy)TDigestCommandsc                 2    | j                  t        |d|      S )z
        Allocate the memory and initialize the t-digest.
        For more information see `TDIGEST.CREATE <https://redis.io/commands/tdigest.create>`_.
        COMPRESSION)r   TDIGEST_CREATE)r   r   compressions      r   r   zTDigestCommands.createl  s    
 ##NCTTr   c                 .    | j                  t        |      S )z
        Reset the sketch `key` to zero - empty out the sketch and re-initialize it.
        For more information see `TDIGEST.RESET <https://redis.io/commands/tdigest.reset>`_.
        )r   TDIGEST_RESETr@   s     r   resetzTDigestCommands.resets  s    
 ##M377r   c                 2     | j                   t        |g| S )z
        Adds one or more observations to a t-digest sketch `key`.

        For more information see `TDIGEST.ADD <https://redis.io/commands/tdigest.add>`_.
        )r   TDIGEST_ADD)r   r   valuess      r   r   zTDigestCommands.addz  s     $t##K>v>>r   NF)r   overridec                    ||g|}||j                  d|g       |r|j                  d        | j                  t        g| S )a  
        Merges all of the values from `keys` to 'destination-key' sketch.
        It is mandatory to provide the `num_keys` before passing the input keys and
        the other (optional) arguments.
        If `destination_key` already exists its values are merged with the input keys.
        If you wish to override the destination key contents use the `OVERRIDE` parameter.

        For more information see `TDIGEST.MERGE <https://redis.io/commands/tdigest.merge>`_.
        r   OVERRIDE)extendr   r   TDIGEST_MERGE)r   destination_keynum_keysr   r   keysr   s          r   mergezTDigestCommands.merge  sQ     "83d3"MM=+67MM*%#t##M;F;;r   c                 .    | j                  t        |      S )z
        Return minimum value from the sketch `key`. Will return DBL_MAX if the sketch is empty.
        For more information see `TDIGEST.MIN <https://redis.io/commands/tdigest.min>`_.
        )r   TDIGEST_MINr@   s     r   minzTDigestCommands.min      
 ##K55r   c                 .    | j                  t        |      S )z
        Return maximum value from the sketch `key`. Will return DBL_MIN if the sketch is empty.
        For more information see `TDIGEST.MAX <https://redis.io/commands/tdigest.max>`_.
        )r   TDIGEST_MAXr@   s     r   maxzTDigestCommands.max  r   r   c                 4     | j                   t        ||g| S )ah  
        Returns estimates of one or more cutoffs such that a specified fraction of the
        observations added to this t-digest would be less than or equal to each of the
        specified cutoffs. (Multiple quantiles can be returned with one call)
        For more information see `TDIGEST.QUANTILE <https://redis.io/commands/tdigest.quantile>`_.
        )r   TDIGEST_QUANTILE)r   r   quantile	quantiless       r   r   zTDigestCommands.quantile  s!     $t##$4c8PiPPr   c                 4     | j                   t        ||g| S )z
        Return double fraction of all points added which are <= value.
        For more information see `TDIGEST.CDF <https://redis.io/commands/tdigest.cdf>`_.
        )r   TDIGEST_CDFr   r   valuer   s       r   cdfzTDigestCommands.cdf  s     
 $t##KeEfEEr   c                 .    | j                  t        |      S )z
        Return Compression, Capacity, Merged Nodes, Unmerged Nodes, Merged Weight, Unmerged Weight
        and Total Compressions.
        For more information see `TDIGEST.INFO <https://redis.io/commands/tdigest.info>`_.
        )r   TDIGEST_INFOr@   s     r   rA   zTDigestCommands.info  s     ##L#66r   c                 2    | j                  t        |||      S )z
        Return mean value from the sketch, excluding observation values outside
        the low and high cutoff quantiles.
        For more information see `TDIGEST.TRIMMED_MEAN <https://redis.io/commands/tdigest.trimmed_mean>`_.
        )r   TDIGEST_TRIMMED_MEAN)r   r   low_cut_quantilehigh_cut_quantiles       r   trimmed_meanzTDigestCommands.trimmed_mean  s"     ## #'79J
 	
r   c                 4     | j                   t        ||g| S )a  
        Retrieve the estimated rank of value (the number of observations in the sketch
        that are smaller than value + half the number of observations that are equal to value).

        For more information see `TDIGEST.RANK <https://redis.io/commands/tdigest.rank>`_.
        )r   TDIGEST_RANKr   s       r   rankzTDigestCommands.rank  s      $t##L#uFvFFr   c                 4     | j                   t        ||g| S )a!  
        Retrieve the estimated rank of value (the number of observations in the sketch
        that are larger than value + half the number of observations that are equal to value).

        For more information see `TDIGEST.REVRANK <https://redis.io/commands/tdigest.revrank>`_.
        )r   TDIGEST_REVRANKr   s       r   revrankzTDigestCommands.revrank  s      $t##OS%I&IIr   c                 4     | j                   t        ||g| S )z
        Retrieve an estimation of the value with the given rank.

        For more information see `TDIGEST.BY_RANK <https://redis.io/commands/tdigest.by_rank>`_.
        )r   TDIGEST_BYRANKr   r   r   rankss       r   byrankzTDigestCommands.byrank  s      $t##NCFFFr   c                 4     | j                   t        ||g| S )z
        Retrieve an estimation of the value with the given reverse rank.

        For more information see `TDIGEST.BY_REVRANK <https://redis.io/commands/tdigest.by_revrank>`_.
        )r   TDIGEST_BYREVRANKr   s       r   	byrevrankzTDigestCommands.byrevrank  s!     $t##$5sDI5IIr   )d   )rG   rH   rI   r   r   r   r   r   r   r   r   rA   r   r   r   r   r   rL   r   r   r   r   k  sY    U8? CGQV <"66QF7
GJGJr   r   c                   8    e Zd ZdZd Zd Zd Zd Zg fdZd Z	y)	CMSCommandszCount-Min Sketch Commandsc                 2    | j                  t        |||      S )z
        Initialize a Count-Min Sketch `key` to dimensions (`width`, `depth`) specified by user.
        For more information see `CMS.INITBYDIM <https://redis.io/commands/cms.initbydim>`_.
        )r   CMS_INITBYDIM)r   r   rv   rw   s       r   	initbydimzCMSCommands.initbydim  s    
 ##M3uEEr   c                 2    | j                  t        |||      S )z
        Initialize a Count-Min Sketch `key` to characteristics (`error`, `probability`) specified by user.
        For more information see `CMS.INITBYPROB <https://redis.io/commands/cms.initbyprob>`_.
        )r   CMS_INITBYPROB)r   r   r)   probabilitys       r   
initbyprobzCMSCommands.initbyprob  s    
 ##NCLLr   c                 \    |g}| j                  |||        | j                  t        g| S )a  
        Add/increase `items` to a Count-Min Sketch `key` by ''increments''.
        Both `items` and `increments` are lists.
        For more information see `CMS.INCRBY <https://redis.io/commands/cms.incrby>`_.

        Example:

        >>> cmsincrby('A', ['foo'], [1])
        )r|   r   
CMS_INCRBYr~   s        r   r   zCMSCommands.incrby  s5     ((
C#t##J888r   c                 2     | j                   t        |g| S )z
        Return count for an `item` from `key`. Multiple items can be queried with one call.
        For more information see `CMS.QUERY <https://redis.io/commands/cms.query>`_.
        )r   	CMS_QUERYr    s      r   r   zCMSCommands.query  s    
 $t##Is;U;;r   c                 f    ||g}||z  }| j                  ||        | j                  t        g| S )an  
        Merge `numKeys` of sketches into `destKey`. Sketches specified in `srcKeys`.
        All sketches must have identical width and depth.
        `Weights` can be used to multiply certain sketches. Default weight is 1.
        Both `srcKeys` and `weights` are lists.
        For more information see `CMS.MERGE <https://redis.io/commands/cms.merge>`_.
        )append_weightsr   	CMS_MERGE)r   destKeynumKeyssrcKeysweightsr   s         r   r   zCMSCommands.merge  s@     7#'FG,#t##I777r   c                 .    | j                  t        |      S )z
        Return width, depth and total count of the sketch.
        For more information see `CMS.INFO <https://redis.io/commands/cms.info>`_.
        )r   CMS_INFOr@   s     r   rA   zCMSCommands.info  s    
 ##Hc22r   N)
rG   rH   rI   rJ   r   r   r   r   r   rA   rL   r   r   r   r     s*    #FM9< 8: 83r   r   N)=redis.clientr   redis.exceptionsr   redis.utilsr   r   r   r   r   r(   r-   r1   r5   r:   r?   rC   rR   rV   rX   r[   r_   rb   rd   rf   ri   rl   rn   rp   r   r   r   r   r   r   rt   rz   r}   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rN   rr   r   r   rL   r   r   <module>r      sF   % ( >
	
		



			
	
!
		

		!% - #!' r2 r2jt2 t2n@4 @4FxJ xJv83 83r   