
    +h@i                       d dl Z d dlZd dlZd dlmZmZmZmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZ d dlmZ d dlmZmZmZmZ d dlmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+ ddl,m-Z- erd dl.m/Z0 d dl1m/Z/ eeef   Z2 G d	 d
e      Z3e3Z4 G d de      Z5e5Z6 G d de5      Z6 G d d      Z7 G d de      Z8 G d de8      Z9 G d de      Z:e:Z; G d de      Z< G d de<      Z= G d de      Z>e>Z? G d de      Z@e@ZA G d d e      ZBeBZC G d! d"e      ZDeDZE G d# d$e      ZFeFZG G d% d&      ZH G d' d(      ZI G d) d*e      ZJeJZK G d+ d,e      ZL G d- d.eL      ZM G d/ d0e      ZNeNZO G d1 d2e      ZP G d3 d&      ZH G d4 d5eP      ZQ G d6 d7e      ZReRZS G d8 d9      ZTeTZU G d: d;      ZVeVZW G d< d=e8eDeFeNe:e<e>e@eB      ZX G d> d?e9eEeGeOe;e=e?eAeC      ZY G d@ dAe3eReXe5ePeJeLeTeV      ZZ G dB dCe4eSeYe6eQeKeMeUeW      Z[y)D    N)TYPE_CHECKINGAnyAsyncIterator	AwaitableCallableDictIterableIteratorListMappingOptionalSequenceSetTupleUnion)Literal)ConnectionError	DataErrorNoScriptError
RedisError)
AbsExpiryTAnyKeyTBitfieldOffsetTChannelTCommandsProtocol	ConsumerT
EncodableTExpiryTFieldTGroupTKeysTKeyTPatternTScriptTextT	StreamIdTTimeoutSecTZScoreBoundT   )list_or_args)Redisc                      e Zd ZdZd#deedf   defdZd ZdedefdZ	d#d	ee
df   defd
ZdedefdZdefdZdefdZd#dee
df   defdZdefdZdefdZdefdZ	 	 	 	 	 	 	 	 	 	 	 	 	 d$dedededeeee   df   deeee   df   deee      deee      deee      deee      deeeeef         dededededefd Zdefd!Zdefd"Zy)%ACLCommandszX
    Redis Access Control List (ACL) commands.
    see: https://redis.io/topics/acl
    Ncategoryreturnc                 <    |r|gng } | j                   dg|i |S )a?  
        Returns a list of categories or commands within a category.

        If ``category`` is not supplied, returns a list of all categories.
        If ``category`` is supplied, returns a list of all commands within
        that category.

        For more information see https://redis.io/commands/acl-cat
        zACL CATexecute_command)selfr-   kwargspiecess       F/var/www/html/venv/lib/python3.12/site-packages/redis/commands/core.pyacl_catzACLCommands.acl_cat=   s,     2:H:r#t##IAA&AA    c                 0     | j                   d|g|i |S )z
        Simulate the execution of a given command by a given ``username``.

        For more information see https://redis.io/commands/acl-dryrun
        z
ACL DRYRUNr0   )r2   usernameargsr3   s       r5   
acl_dryrunzACLCommands.acl_dryrunJ   s#     $t##L(LTLVLLr7   r9   c                 .     | j                   dg|i |S )z
        Delete the ACL for the specified ``username``s

        For more information see https://redis.io/commands/acl-deluser
        zACL DELUSERr0   r2   r9   r3   s      r5   acl_deluserzACLCommands.acl_deluserR   s!     $t##MGHGGGr7   bitsc                     g }|	 t        |      }|dk  s|dkD  rt        	  | j                  dg|i |S # t        $ r t        d      w xY w)zGenerate a random password value.
        If ``bits`` is supplied then use this number of bits, rounded to
        the next multiple of 4.
        See: https://redis.io/commands/acl-genpass
        r   i   z?genpass optionally accepts a bits argument, between 0 and 4096.zACL GENPASS)int
ValueErrorr   r1   )r2   r?   r3   r4   bs        r5   acl_genpasszACLCommands.acl_genpassZ   su     Iq5AH$$ % $t##MEFEfEE	  U s	   8 Ac                 *     | j                   d|fi |S )z
        Get the ACL details for the specified ``username``.

        If ``username`` does not exist, return None

        For more information see https://redis.io/commands/acl-getuser
        zACL GETUSERr0   r=   s      r5   acl_getuserzACLCommands.acl_getuserl   s     $t##M8FvFFr7   c                 &     | j                   di |S )zThe ACL HELP command returns helpful text describing
        the different subcommands.

        For more information see https://redis.io/commands/acl-help
        )zACL HELPr0   r2   r3   s     r5   acl_helpzACLCommands.acl_helpv        $t##9&99r7   c                 &     | j                   di |S )z~
        Return a list of all ACLs on the server

        For more information see https://redis.io/commands/acl-list
        )zACL LISTr0   rH   s     r5   acl_listzACLCommands.acl_list~   rJ   r7   countc                     g }|,t        |t              st        d      |j                  |        | j                  dg|i |S )z
        Get ACL logs as a list.
        :param int count: Get logs[0:count].
        :rtype: List.

        For more information see https://redis.io/commands/acl-log
        z ACL LOG count must be an integerACL LOG)
isinstancerA   r   appendr1   )r2   rM   r3   r:   s       r5   acl_logzACLCommands.acl_log   sN     eS) BCCKK#t##I????r7   c                 4    dg} | j                   dg|i |S )z~
        Reset ACL logs.
        :rtype: Boolean.

        For more information see https://redis.io/commands/acl-log
        s   RESETrO   r0   )r2   r3   r:   s      r5   acl_log_resetzACLCommands.acl_log_reset   s(     z#t##I????r7   c                 &     | j                   di |S )a  
        Load ACL rules from the configured ``aclfile``.

        Note that the server must be configured with the ``aclfile``
        directive to be able to load ACL rules from an aclfile.

        For more information see https://redis.io/commands/acl-load
        )zACL LOADr0   rH   s     r5   acl_loadzACLCommands.acl_load        $t##9&99r7   c                 &     | j                   di |S )a  
        Save ACL rules to the configured ``aclfile``.

        Note that the server must be configured with the ``aclfile``
        directive to be able to save ACL rules to an aclfile.

        For more information see https://redis.io/commands/acl-save
        )zACL SAVEr0   rH   s     r5   acl_savezACLCommands.acl_save   rW   r7   enablednopass	passwordshashed_passwords
categoriescommandskeyschannels	selectorsreset
reset_keysreset_channelsreset_passwordsc                    | j                         }|g}|r|j                  d       |r|j                  d       |r|j                  d       |r|j                  d       |r|j                  d       n|j                  d       |s|r|rt        d      |rt        |g       }t	        |      D ]v  \  }}|j                  |      }|j                  d      r|j                  d	|d
d z         @|j                  d      r|j                  d|d
d z         it        d| d       |rt        |g       }t	        |      D ]v  \  }}|j                  |      }|j                  d      r|j                  d|d
d z         @|j                  d      r|j                  d|d
d z         it        d| d       |r|j                  d       |r|D ]  }|j                  |      }|j                  d      r|j                  |       7|j                  d      r|j                  d|d
d z         `|j                  d      r|j                  |       |j                  d      r|j                  d|d
d z         t        d|j                  |d       d       |rk|D ]f  }|j                  |      }|j                  d      s1|j                  d      s t        d|j                  |d       d      |j                  |       h |rP|D ]K  }|j                  |      }|j                  d      s|j                  d      sd|z  }|j                  |       M |	r,|	D ]'  }|j                  |      }|j                  d |z         ) |
r|
D ]  \  }}|j                  |      }|j                  d      s1|j                  d      s t        d|j                  |d       d      |j                  |      }|j                  d      s|j                  d      sd|z  }|j                  d!||fz           | j                  d"g|i |S )#a  
        Create or update an ACL user.

        Create or update the ACL for ``username``. If the user already exists,
        the existing ACL is completely overwritten and replaced with the
        specified values.

        ``enabled`` is a boolean indicating whether the user should be allowed
        to authenticate or not. Defaults to ``False``.

        ``nopass`` is a boolean indicating whether the can authenticate without
        a password. This cannot be True if ``passwords`` are also specified.

        ``passwords`` if specified is a list of plain text passwords
        to add to or remove from the user. Each password must be prefixed with
        a '+' to add or a '-' to remove. For convenience, the value of
        ``passwords`` can be a simple prefixed string when adding or
        removing a single password.

        ``hashed_passwords`` if specified is a list of SHA-256 hashed passwords
        to add to or remove from the user. Each hashed password must be
        prefixed with a '+' to add or a '-' to remove. For convenience,
        the value of ``hashed_passwords`` can be a simple prefixed string when
        adding or removing a single password.

        ``categories`` if specified is a list of strings representing category
        permissions. Each string must be prefixed with either a '+' to add the
        category permission or a '-' to remove the category permission.

        ``commands`` if specified is a list of strings representing command
        permissions. Each string must be prefixed with either a '+' to add the
        command permission or a '-' to remove the command permission.

        ``keys`` if specified is a list of key patterns to grant the user
        access to. Keys patterns allow '*' to support wildcard matching. For
        example, '*' grants access to all keys while 'cache:*' grants access
        to all keys that are prefixed with 'cache:'. ``keys`` should not be
        prefixed with a '~'.

        ``reset`` is a boolean indicating whether the user should be fully
        reset prior to applying the new ACL. Setting this to True will
        remove all existing passwords, flags and privileges from the user and
        then apply the specified rules. If this is False, the user's existing
        passwords, flags and privileges will be kept and any new specified
        rules will be applied on top.

        ``reset_keys`` is a boolean indicating whether the user's key
        permissions should be reset prior to applying any new key permissions
        specified in ``keys``. If this is False, the user's existing
        key permissions will be kept and any new specified key permissions
        will be applied on top.

        ``reset_channels`` is a boolean indicating whether the user's channel
        permissions should be reset prior to applying any new channel permissions
        specified in ``channels``.If this is False, the user's existing
        channel permissions will be kept and any new specified channel permissions
        will be applied on top.

        ``reset_passwords`` is a boolean indicating whether to remove all
        existing passwords and the 'nopass' flag from the user prior to
        applying any new passwords specified in 'passwords' or
        'hashed_passwords'. If this is False, the user's existing passwords
        and 'nopass' status will be kept and any new specified passwords
        or hashed_passwords will be applied on top.

        For more information see https://redis.io/commands/acl-setuser
        s   resets	   resetkeyss   resetchannelss	   resetpasss   ons   offz@Cannot set 'nopass' and supply 'passwords' or 'hashed_passwords'   +s   >%sr(   N   -s   <%sz	Password z6 must be prefixed with a "+" to add or a "-" to removes   #%ss   !%szHashed password s   nopasss   +@s   +@%ss   -@s   -@%sz
Category "T)forcez"" must be prefixed with "+" or "-"z	Command "   %   ~s   ~%ss   &%ss   (%s %s)zACL SETUSER)	get_encoderrQ   r   r)   	enumerateencode
startswithdecoder1   )r2   r9   rZ   r[   r\   r]   r^   r_   r`   ra   rb   rc   rd   re   rf   r3   encoderr4   ipasswordhashed_passwordr-   cmdkeychannels                            r5   acl_setuserzACLCommands.acl_setuser   sq   j ""$$,:MM(#MM,'MM*+MM,'MM% MM&!)vR   %Y3I(3 
8">>(3&&t,MM&8AB<"78((.MM&8AB<"78##A3 '8 9 
   ,,<bA&/0@&A 
"?").."A"--d3MM&?12+>">?$//5MM&?12+>">?#*1# .8 9 
 MM)$& ">>(3&&u-MM(+((.MM'HQRL"89((/MM(+((.MM'HQRL"89#$W^^HD^%I$J K; ;    #nnS)~~d+CNN44H##GNN3dN$C#D E; ;  c"#  #nnS)~~d+CNN44H 3,Cc"	# # 0!..1fw./0 % 7SnnS)~~d+CNN44H##GNN3dN$C#D E; ; 
 nnS)~~d+CNN44H 3,CjC:567 $t##MEFEfEEr7   c                 &     | j                   di |S )zReturns a list of all registered users on the server.

        For more information see https://redis.io/commands/acl-users
        )z	ACL USERSr0   rH   s     r5   	acl_userszACLCommands.acl_users  s    
 $t##:6::r7   c                 &     | j                   di |S )z{Get the username for the current connection

        For more information see https://redis.io/commands/acl-whoami
        )z
ACL WHOAMIr0   rH   s     r5   
acl_whoamizACLCommands.acl_whoami  s    
 $t##;F;;r7   N)FFNNNNNNNFFFF)__name__
__module____qualname____doc__r   str	ResponseTr6   r;   r>   rA   rD   rF   rI   rL   rR   rT   rV   rY   boolr	   r   r"   r   r   ry   r{   r}    r7   r5   r,   r,   7   s'   
Bc4i 0 Bi BMHS Hy HFc4i 0 Fi F$GC Gi G:I ::I :@U39- @9 @ @ @	:I 	:	:I 	: 59<@.2,0)-15:> $ %GFGF GF 	GF
 hsmT12GF  Xc]D 89GF Xc]+GF 8C=)GF x~&GF 8H-.GF HU39%567GF GF GF GF GF" 
#GFR;Y ;<i <r7   r,   c                   r   e Zd ZdZddedee   fdZd Zdded	e	fd
Z
d	e	fdZded	e	fdZ	 	 	 	 	 	 ddeedf   deedf   deedf   deedf   deedf   ded	e	fdZd	e	fdZdg fdeedf   dee   d	e	fdZd	e	fdZd	e	fdZdeed   ed   ed   f   d	e	fdZd	e	fdZdg d d d d fd!eedf   d"ee   d#ed$ed%ed&ed	e	fd'Zdg d d d d fd!eedf   d"ee   d#ed$ed%ed&ed	e	fd(Zddg d d d d fd)ed!eedf   d"ee   d#ed$ed%ed&ed	e	fd*Zd	e	fd+Zd,ed	e	fd-Zd.ed/ed	e	fd0Z 	 dded1ed	e	fd2Z!dd3ed4ed	e	fd5Z"d	e	fd6Z#d7ed	ee$e   ef   fd8Z%d7ed	ee$e   ef   fd9Z&d: Z'dd;Z(d	e	fd<Z)	 	 	 dd=ee   d>ee   d?ee   d	e	fd@Z*dAee   d	eeeee   f      fdBZ+dC Z,	 dd?e-dAee-   d	e	fdDZ.d,ed/edAeeeef      d	e	fdEZ/d	e	fdFZ0d	e	fdGZ1d	e	fdHZ2dIed	e	fdJZ3ddKZ4d/ed	e	fdLZ5ddMed	e	fdNZ6ddMed	e	fdOZ7d	e	fdPZ8dQedRefdSZ9dTedUed	e	fdVZ:dWed	e	fdXZ;	 ddYeedf   dAee   d	e	fdZZ<d	e	fd[Z=d\ Z>d] Z?d^eee@f   d	e	fd_ZAd	e	fd`ZB	 	 	 ddaedbedceCdded3edeedfedgeedf   d	e	fdhZDdiedIed	e	fdjZEddkZFddlZGd	e	fdmZHd	e	fdnZI	 ddIedoeedf   d	e	fdpZJd	e	fdqZKdr ZLdsed	e	fdtZMd	e	fduZNdved	e	fdwZOd	e	fdxZPd	e	fdyZQd	e	fdzZRd	e	fd{ZS	 	 	 	 	 dd|ed}ed~ededed	dfdZT	 ddaeedf   dbeedf   d	e	fdZUddeedf   d	e	fdZVd	e	fdZWd	e	fdZXd	e	fdZYded3ed	e	fdZZdeded3ed	e	fdZ[d Z\d Z]y)ManagementCommandsz#
    Redis management commands
    Nrt   r9   c                 z    g }||j                  |       |j                  |        | j                  dg|i |S )a  
        Authenticates the user. If you do not pass username, Redis will try to
        authenticate for the "default" user. If you do pass username, it will
        authenticate for the given user.
        For more information see https://redis.io/commands/auth
        AUTHrQ   r1   )r2   rt   r9   r3   r4   s        r5   authzManagementCommands.auth  sD     MM(#h#t##F>V>v>>r7   c                 &     | j                   di |S )zTell the Redis server to rewrite the AOF file from data in memory.

        For more information see https://redis.io/commands/bgrewriteaof
        )BGREWRITEAOFr0   rH   s     r5   bgrewriteaofzManagementCommands.bgrewriteaof  s    
 $t##=f==r7   Tscheduler.   c                 X    g }|r|j                  d        | j                  dg|i |S )z
        Tell the Redis server to save its data to disk.  Unlike save(),
        this method is asynchronous and returns immediately.

        For more information see https://redis.io/commands/bgsave
        SCHEDULEBGSAVEr   )r2   r   r3   r4   s       r5   bgsavezManagementCommands.bgsave  s5     MM*%#t##H@v@@@r7   c                 $    | j                  d      S )z
        Provide information on the role of a Redis instance in
        the context of replication, by returning if the instance
        is currently a master, slave, or sentinel.

        For more information see https://redis.io/commands/role
        ROLEr0   r2   s    r5   rolezManagementCommands.role  s     ##F++r7   addressc                 *     | j                   d|fi |S )zDisconnects the client at ``address`` (ip:port)

        For more information see https://redis.io/commands/client-kill
        CLIENT KILLr0   )r2   r   r3   s      r5   client_killzManagementCommands.client_kill  s    
 $t##M7EfEEr7   _id_typeaddrskipmeladdruserc                    g }|>d}	t        |      j                         |	vrt        d|	      |j                  d|f       |@t	        |t
              st        d      |r|j                  d       n|j                  d       ||j                  d|f       ||j                  d|f       ||j                  d	|f       ||j                  d
|f       |st        d       | j                  dg|i |S )a  
        Disconnects client(s) using a variety of filter options
        :param _id: Kills a client by its unique ID field
        :param _type: Kills a client by type where type is one of 'normal',
        'master', 'slave' or 'pubsub'
        :param addr: Kills a client by its 'address:port'
        :param skipme: If True, then the client calling the command
        will not get killed even if it is identified by one of the filter
        options. If skipme is not provided, the server defaults to skipme=True
        :param laddr: Kills a client by its 'local (bind) address:port'
        :param user: Kills a client for a specific user name
        )normalmasterslavepubsubz CLIENT KILL type must be one of    TYPEz!CLIENT KILL skipme must be a bool)   SKIPMEs   YES)r      NO   IDs   ADDRs   LADDRs   USERzVCLIENT KILL <filter> <value> ... ... <filter> <value> must specify at least one filterr   )r   lowerr   extendrP   r   r1   )
r2   r   r   r   r   r   r   r3   r:   client_typess
             r5   client_kill_filterz%ManagementCommands.client_kill_filter  s   , BL5z!5"B<BR STTKK%()fd+ CDD/0./?KK%KK$(KK5)*KK$(;  $t##MCDCFCCr7   c                 &     | j                   di |S )z
        Returns information and statistics about the current
        client connection.

        For more information see https://redis.io/commands/client-info
        )zCLIENT INFOr0   rH   s     r5   client_infozManagementCommands.client_info  s     $t##<V<<r7   	client_idc                 l   g }|Md}t        |      j                         |vrt        d|      |j                  d       |j                  |       t	        |t
              st        d      |r1|j                  d       |j                  dj                  |              | j                  dg|i |S )ak  
        Returns a list of currently connected clients.
        If type of client specified, only that type will be returned.

        :param _type: optional. one of the client types (normal, master,
         replica, pubsub)
        :param client_id: optional. a list of client ids

        For more information see https://redis.io/commands/client-list
        )r   r   replicar   z!CLIENT LIST _type must be one of r   zclient_id must be a listr    zCLIENT LIST)r   r   r   rQ   rP   listjoinr1   )r2   r   r   r3   r:   r   s         r5   client_listzManagementCommands.client_list  s     DL5z!5"CLCS TUUKK KK)T*677KKKK+,#t##MCDCFCCr7   c                 &     | j                   di |S )z
        Returns the current connection name

        For more information see https://redis.io/commands/client-getname
        )zCLIENT GETNAMEr0   rH   s     r5   client_getnamez!ManagementCommands.client_getname       $t##???r7   c                 &     | j                   di |S )z
        Returns the ID (an integer) of the client to whom we are
        redirecting tracking notifications.

        see: https://redis.io/commands/client-getredir
        )zCLIENT GETREDIRr0   rH   s     r5   client_getredirz"ManagementCommands.client_getredir%  s     $t##@@@r7   replyONOFFSKIPc                 V    g d}||vrt        d|       | j                  d|fi |S )am  
        Enable and disable redis server replies.

        ``reply`` Must be ON OFF or SKIP,
        ON - The default most with server replies to commands
        OFF - Disable server responses to commands
        SKIP - Skip the response of the immediately following command.

        Note: When setting OFF or SKIP replies, you will need a client object
        with a timeout specified in seconds, and will need to catch the
        TimeoutError.
        The test_client_reply unit test illustrates this, and
        conftest.py has a client with a timeout.

        See https://redis.io/commands/client-reply
        )r   r   r   zCLIENT REPLY must be one of zCLIENT REPLYr   r1   )r2   r   r3   repliess       r5   client_replyzManagementCommands.client_reply.  s>    & (:7+FGG#t##NEDVDDr7   c                 &     | j                   di |S )zy
        Returns the current connection id

        For more information see https://redis.io/commands/client-id
        )z	CLIENT IDr0   rH   s     r5   r   zManagementCommands.client_idF       $t##:6::r7   Fclientidprefixbcastoptinoptoutnoloopc           	      0    | j                  d||||||      S )z
        Turn on the tracking mode.
        For more information about the options look at client_tracking func.

        See https://redis.io/commands/client-tracking
        Tclient_trackingr2   r   r   r   r   r   r   s          r5   client_tracking_onz%ManagementCommands.client_tracking_onN  s&     ##(FE5&&
 	
r7   c           	      0    | j                  d||||||      S )z
        Turn off the tracking mode.
        For more information about the options look at client_tracking func.

        See https://redis.io/commands/client-tracking
        Fr   r   s          r5   client_tracking_offz&ManagementCommands.client_tracking_offa  s&     ##8VUE66
 	
r7   onc                 h   t        |      dk7  r|du rt        d      |rdgndg}	||	j                  d|g       |D ]  }
|	j                  d|
g        |r|	j                  d       |r|	j                  d	       |r|	j                  d
       |r|	j                  d        | j                  dg|	 S )a  
        Enables the tracking feature of the Redis server, that is used
        for server assisted client side caching.

        ``on`` indicate for tracking on or tracking off. The dafualt is on.

        ``clientid`` send invalidation messages to the connection with
        the specified ID.

        ``bcast`` enable tracking in broadcasting mode. In this mode
        invalidation messages are reported for all the prefixes
        specified, regardless of the keys requested by the connection.

        ``optin``  when broadcasting is NOT active, normally don't track
        keys in read only commands, unless they are called immediately
        after a CLIENT CACHING yes command.

        ``optout`` when broadcasting is NOT active, normally track keys in
        read only commands, unless they are called immediately after a
        CLIENT CACHING no command.

        ``noloop`` don't send notifications about keys modified by this
        connection itself.

        ``prefix``  for broadcasting, register a given key prefix, so that
        notifications will be provided only for keys starting with this string.

        See https://redis.io/commands/client-tracking
        r   Fz"Prefix can only be used with bcastr   r   REDIRECTPREFIXBCASTOPTINOPTOUTNOLOOPzCLIENT TRACKING)lenr   r   rQ   r1   )r2   r   r   r   r   r   r   r   r3   r4   ps              r5   r   z"ManagementCommands.client_trackingt  s    R v;!@AA$E7MM:x01 	)AMM8Q-(	)MM'"MM'"MM(#MM(##t##$5???r7   c                 &     | j                   di |S )z
        Returns the information about the current client connection's
        use of the server assisted client side cache.

        See https://redis.io/commands/client-trackinginfo
        )zCLIENT TRACKINGINFOr0   rH   s     r5   client_trackinginfoz&ManagementCommands.client_trackinginfo  s     $t##DVDDr7   namec                 *     | j                   d|fi |S )ag  
        Sets the current connection name

        For more information see https://redis.io/commands/client-setname

        .. note::
           This method sets client name only for **current** connection.

           If you want to set a common name for all connections managed
           by this client, use ``client_name`` constructor argument.
        zCLIENT SETNAMEr0   )r2   r   r3   s      r5   client_setnamez!ManagementCommands.client_setname  s     $t##$4dEfEEr7   attrvaluec                 ,     | j                   d||fi |S )z
        Sets the current connection library name or version
        For mor information see https://redis.io/commands/client-setinfo
        zCLIENT SETINFOr0   )r2   r   r   r3   s       r5   client_setinfoz!ManagementCommands.client_setinfo  s!    
 $t##$4dELVLLr7   errorc                 f    dt        |      g}|r|j                  d        | j                  |i |S )aB  
        Unblocks a connection by its client id.
        If ``error`` is True, unblocks the client with a special error message.
        If ``error`` is False (default), the client is unblocked using the
        regular timeout mechanism.

        For more information see https://redis.io/commands/client-unblock
        zCLIENT UNBLOCKs   ERROR)rA   rQ   r1   )r2   r   r   r3   r:   s        r5   client_unblockz!ManagementCommands.client_unblock  s9     !#i.1KK!#t##T4V44r7   timeoutallc                     dt        |      g}t        |t              st        d      |s|j	                  d        | j
                  |i |S )a  
        Suspend all the Redis clients for the specified amount of time.


        For more information see https://redis.io/commands/client-pause

        :param timeout: milliseconds to pause clients
        :param all: If true (default) all client commands are blocked.
        otherwise, clients are only blocked if they attempt to execute
        a write command.
        For the WRITE mode, some commands have special behavior:
        EVAL/EVALSHA: Will block client for all scripts.
        PUBLISH: Will block client.
        PFCOUNT: Will block client.
        WAIT: Acknowledgments will be delayed, so this command will
        appear blocked.
        zCLIENT PAUSEz'CLIENT PAUSE timeout must be an integerWRITE)r   rP   rA   r   rQ   r1   )r2   r   r   r3   r:   s        r5   client_pausezManagementCommands.client_pause  sO    $ G-'3'EFFKK #t##T4V44r7   c                 &     | j                   di |S )zv
        Unpause all redis clients

        For more information see https://redis.io/commands/client-unpause
        )zCLIENT UNPAUSEr0   rH   s     r5   client_unpausez!ManagementCommands.client_unpause  r   r7   modec                 &    | j                  d|      S )z
        Sets the client eviction mode for the current connection.

        For more information see https://redis.io/commands/client-no-evict
        zCLIENT NO-EVICTr0   r2   r   s     r5   client_no_evictz"ManagementCommands.client_no_evict  s     ##$5t<<r7   c                 &    | j                  d|      S )aK  
        # The command controls whether commands sent by the client will alter
        # the LRU/LFU of the keys they access.
        # When turned on, the current client will not change LFU/LRU stats,
        # unless it sends the TOUCH command.

        For more information see https://redis.io/commands/client-no-touch
        zCLIENT NO-TOUCHr0   r   s     r5   client_no_touchz"ManagementCommands.client_no_touch  s     ##$5t<<r7   c                 &     | j                   di |S )z
        Returns dict reply of details about all Redis commands.

        For more information see https://redis.io/commands/command
        )COMMANDr0   rH   s     r5   commandzManagementCommands.command  s     $t##888r7   c                     t        d      Nz<COMMAND INFO is intentionally not implemented in the client.NotImplementedErrorrH   s     r5   command_infozManagementCommands.command_info      !J
 	
r7   c                 &     | j                   di |S )N)COMMAND COUNTr0   rH   s     r5   command_countz ManagementCommands.command_count  s    #t##>v>>r7   moduler-   patternc                     g }||j                  d|g       ||j                  d|g       ||j                  d|g       |r|j                  dd        | j                  dg| S )ay  
        Return an array of the server's command names.
        You can use one of the following filters:
        ``module``: get the commands that belong to the module
        ``category``: get the commands in the ACL category
        ``pattern``: get the commands that match the given pattern

        For more information see https://redis.io/commands/command-list/
        MODULEACLCATPATTERNr   FILTERBYzCOMMAND LIST)r   insertr1   )r2   r  r-   r  r4   s        r5   command_listzManagementCommands.command_list"  sw     MM8V,-MM8X./MM9g./MM!Z(#t##N<V<<r7   r:   c                 (     | j                   dg| S )z
        Returns array of keys from a full Redis command and their usage flags.

        For more information see https://redis.io/commands/command-getkeysandflags
        zCOMMAND GETKEYSANDFLAGSr0   r2   r:   s     r5   command_getkeysandflagsz*ManagementCommands.command_getkeysandflags>  s     $t##$=EEEr7   c                     t        d      )m
        This function throws a NotImplementedError since it is intentionally
        not supported.
        z<COMMAND DOCS is intentionally not implemented in the client.r   r  s     r5   command_docszManagementCommands.command_docsF  s    
 "J
 	
r7   c                 0     | j                   d|g|i |S )z
        Return a dictionary of configuration based on the ``pattern``

        For more information see https://redis.io/commands/config-get
        z
CONFIG GETr0   )r2   r  r:   r3   s       r5   
config_getzManagementCommands.config_getO  s#     $t##L'KDKFKKr7   c                 2     | j                   d||g|i |S )zwSet config item ``name`` with ``value``

        For more information see https://redis.io/commands/config-set
        z
CONFIG SETr0   )r2   r   r   r:   r3   s        r5   
config_setzManagementCommands.config_setY  s%     $t##L$OOOOr7   c                 &     | j                   di |S )zw
        Reset runtime statistics

        For more information see https://redis.io/commands/config-resetstat
        )zCONFIG RESETSTATr0   rH   s     r5   config_resetstatz#ManagementCommands.config_resetstatf  s     $t##A&AAr7   c                 &     | j                   di |S )z
        Rewrite config file with the minimal change to reflect running config.

        For more information see https://redis.io/commands/config-rewrite
        )zCONFIG REWRITEr0   rH   s     r5   config_rewritez!ManagementCommands.config_rewriten  r   r7   c                 &     | j                   di |S )z
        Returns the number of keys in the current database

        For more information see https://redis.io/commands/dbsize
        )DBSIZEr0   rH   s     r5   dbsizezManagementCommands.dbsizev  s     $t##777r7   rw   c                 *     | j                   d|fi |S )z
        Returns version specific meta information about a given key

        For more information see https://redis.io/commands/debug-object
        zDEBUG OBJECTr0   )r2   rw   r3   s      r5   debug_objectzManagementCommands.debug_object~  s     $t##NCB6BBr7   c                     t        d      )Nz
            DEBUG SEGFAULT is intentionally not implemented in the client.

            For more information see https://redis.io/commands/debug-segfault
            r   rH   s     r5   debug_segfaultz!ManagementCommands.debug_segfault      !
 	
r7   c                 *     | j                   d|fi |S )zw
        Echo the string back from the server

        For more information see https://redis.io/commands/echo
        ECHOr0   )r2   r   r3   s      r5   echozManagementCommands.echo  s     $t##FE<V<<r7   asynchronousc                 X    g }|r|j                  d        | j                  dg|i |S )z
        Delete all keys in all databases on the current host.

        ``asynchronous`` indicates whether the operation is
        executed asynchronously by the server.

        For more information see https://redis.io/commands/flushall
           ASYNCFLUSHALLr   r2   r&  r3   r:   s       r5   flushallzManagementCommands.flushall  s5     KK!#t##J@@@@r7   c                 X    g }|r|j                  d        | j                  dg|i |S )z
        Delete all keys in the current database.

        ``asynchronous`` indicates whether the operation is
        executed asynchronously by the server.

        For more information see https://redis.io/commands/flushdb
        r(  FLUSHDBr   r*  s       r5   flushdbzManagementCommands.flushdb  s5     KK!#t##I????r7   c                 @    ddl m} i }g ||<    | j                  di |S )z
        Initiates a replication stream from the master.

        For more information see https://redis.io/commands/sync
        r   NEVER_DECODESYNCredis.clientr1  r1   r2   r1  optionss      r5   synczManagementCommands.sync  s,     	. "#t##6g66r7   replicationidoffsetc                 F    ddl m} i }g ||<    | j                  d||fi |S )z
        Initiates a replication stream from the master.
        Newer version for `sync`.

        For more information see https://redis.io/commands/sync
        r   r0  PSYNCr4  )r2   r9  r:  r1  r7  s        r5   psynczManagementCommands.psync  s2     	. "#t##G]FNgNNr7   firstsecondc                 ,     | j                   d||fi |S )zg
        Swap two databases

        For more information see https://redis.io/commands/swapdb
        SWAPDBr0   )r2   r>  r?  r3   s       r5   swapdbzManagementCommands.swapdb  s      $t##HeVFvFFr7   indexc                 *     | j                   d|fi |S )zcSelect the Redis logical database at index.

        See: https://redis.io/commands/select
        SELECTr0   )r2   rC  r3   s      r5   selectzManagementCommands.select  s    
 $t##He>v>>r7   sectionc                 X    | | j                   di |S  | j                   d|g|i |S )am  
        Returns a dictionary containing information about the Redis server

        The ``section`` option can be used to select a specific section
        of information

        The section option is not supported by older versions of Redis Server,
        and will generate ResponseError

        For more information see https://redis.io/commands/info
        INFO)rI  r0   )r2   rG  r:   r3   s       r5   infozManagementCommands.info  s>     ?'4''9&99'4''I$I&IIr7   c                 &     | j                   di |S )z
        Return a Python datetime object representing the last time the
        Redis database was saved to disk

        For more information see https://redis.io/commands/lastsave
        )LASTSAVEr0   rH   s     r5   lastsavezManagementCommands.lastsave  s     $t##9&99r7   c                     t        d      )zRaise a NotImplementedError, as the client will not support LATENCY DOCTOR.
        This funcion is best used within the redis-cli.

        For more information see https://redis.io/commands/latency-doctor
        z
            LATENCY DOCTOR is intentionally not implemented in the client.

            For more information see https://redis.io/commands/latency-doctor
            r   r   s    r5   latency_doctorz!ManagementCommands.latency_doctor       "
 	
r7   c                     t        d      )zRaise a NotImplementedError, as the client will not support LATENCY GRAPH.
        This funcion is best used within the redis-cli.

        For more information see https://redis.io/commands/latency-graph.
        z
            LATENCY GRAPH is intentionally not implemented in the client.

            For more information see https://redis.io/commands/latency-graph
            r   r   s    r5   latency_graphz ManagementCommands.latency_graph  rP  r7   version_numbersc                 V    |r | j                   dg|i |S  | j                   di |S )z}
        Get the Redis version and a piece of generative computer art

        See: https://redis.io/commands/lolwut
        zLOLWUT VERSION)LOLWUTr0   )r2   rS  r3   s      r5   lolwutzManagementCommands.lolwut  s;     '4''(8U?UfUU'4'';F;;r7   c                 $    | j                  d      S )zuPerform a full reset on the connection's server side contenxt.

        See: https://redis.io/commands/reset
        RESETr0   r   s    r5   rc   zManagementCommands.reset  s    
 ##G,,r7   hostportr`   destination_dbcopyreplacer   c	                 F   t        |g       }|st        d      g }
|r|
j                  d       |r|
j                  d       |r"|
j                  d       |
j                  |       |
j                  d       |
j                  |        | j                  d||d||g|
i |	S )a  
        Migrate 1 or more keys from the current Redis server to a different
        server specified by the ``host``, ``port`` and ``destination_db``.

        The ``timeout``, specified in milliseconds, indicates the maximum
        time the connection between the two servers can be idle before the
        command is interrupted.

        If ``copy`` is True, the specified ``keys`` are NOT deleted from
        the source server.

        If ``replace`` is True, this operation will overwrite the keys
        on the destination server if they exist.

        If ``auth`` is specified, authenticate to the destination server with
        the password provided.

        For more information see https://redis.io/commands/migrate
        z!MIGRATE requires at least one keys   COPYs   REPLACEs   AUTHs   KEYSMIGRATE )r)   r   rQ   r   r1   )r2   rY  rZ  r`   r[  r   r\  r]  r   r3   r4   s              r5   migratezManagementCommands.migrate%  s    > D"%?@@MM'"MM*%MM'"MM$gd#t##tT2~w
AG
KQ
 	
r7   infotypec                 0     | j                   d||fd|i|S )zJ
        Return the encoding, idletime, or refcount about the key
        OBJECTrb  r0   )r2   rb  rw   r3   s       r5   objectzManagementCommands.objectU  s0     $t##h
.6
:@
 	
r7   c                     t        d      )Nz
            MEMORY DOCTOR is intentionally not implemented in the client.

            For more information see https://redis.io/commands/memory-doctor
            r   rH   s     r5   memory_doctorz ManagementCommands.memory_doctor]  r"  r7   c                     t        d      )Nz
            MEMORY HELP is intentionally not implemented in the client.

            For more information see https://redis.io/commands/memory-help
            r   rH   s     r5   memory_helpzManagementCommands.memory_helpf  r"  r7   c                 &     | j                   di |S )z~
        Return a dictionary of memory stats

        For more information see https://redis.io/commands/memory-stats
        )zMEMORY STATSr0   rH   s     r5   memory_statszManagementCommands.memory_statso       $t##=f==r7   c                 &     | j                   di |S )z
        Return an internal statistics report from the memory allocator.

        See: https://redis.io/commands/memory-malloc-stats
        )zMEMORY MALLOC-STATSr0   rH   s     r5   memory_malloc_statsz&ManagementCommands.memory_malloc_statsw  s     $t##DVDDr7   samplesc                 z    g }t        |t              r|j                  d|g        | j                  d|g|i |S )ap  
        Return the total memory usage for key, its value and associated
        administrative overheads.

        For nested data structures, ``samples`` is the number of elements to
        sample. If left unspecified, the server's default is 5. Use 0 to sample
        all elements.

        For more information see https://redis.io/commands/memory-usage
        s   SAMPLESzMEMORY USAGE)rP   rA   r   r1   )r2   rw   ro  r3   r:   s        r5   memory_usagezManagementCommands.memory_usage  sC     gs#KKW-.#t##NCI$I&IIr7   c                 &     | j                   di |S )z
        Attempts to purge dirty pages for reclamation by allocator

        For more information see https://redis.io/commands/memory-purge
        )zMEMORY PURGEr0   rH   s     r5   memory_purgezManagementCommands.memory_purge  rl  r7   c                     t        d      )r  zALATENCY HISTOGRAM is intentionally not implemented in the client.r   r  s     r5   latency_histogramz$ManagementCommands.latency_histogram  s    
 "O
 	
r7   eventc                 &    | j                  d|      S )z
        Returns the raw data of the ``event``'s latency spikes time series.

        For more information see https://redis.io/commands/latency-history
        zLATENCY HISTORYr0   )r2   rv  s     r5   latency_historyz"ManagementCommands.latency_history  s     ##$5u==r7   c                 $    | j                  d      S )z
        Reports the latest latency events logged.

        For more information see https://redis.io/commands/latency-latest
        zLATENCY LATESTr0   r   s    r5   latency_latestz!ManagementCommands.latency_latest  s     ##$455r7   eventsc                 (     | j                   dg| S )z
        Resets the latency spikes time series of all, or only some, events.

        For more information see https://redis.io/commands/latency-reset
        zLATENCY RESETr0   )r2   r{  s     r5   latency_resetz ManagementCommands.latency_reset  s     $t##O=f==r7   c                 &     | j                   di |S )zh
        Ping the Redis server

        For more information see https://redis.io/commands/ping
        )PINGr0   rH   s     r5   pingzManagementCommands.ping       $t##5f55r7   c                 &     | j                   di |S )zz
        Ask the server to close the connection.

        For more information see https://redis.io/commands/quit
        )QUITr0   rH   s     r5   quitzManagementCommands.quit  r  r7   c                 .     | j                   dg|i |S )a*  
        Update the replication settings of a redis replica, on the fly.

        Examples of valid arguments include:

        NO ONE (set no replication)
        host port (set to the host and port of a redis server)

        For more information see  https://redis.io/commands/replicaof
        	REPLICAOFr0   r2   r:   r3   s      r5   	replicaofzManagementCommands.replicaof  s!     $t##KA$A&AAr7   c                 &     | j                   di |S )z
        Tell the Redis server to save its data to disk,
        blocking until the save is complete

        For more information see https://redis.io/commands/save
        )SAVEr0   rH   s     r5   savezManagementCommands.save       $t##5f55r7   r  nosavenowrj   abortc                 >   |r|rt        d      dg}|r|j                  d       |r|j                  d       |r|j                  d       |r|j                  d       |r|j                  d       	  | j                  |i | t	        d	      # t        $ r Y yw xY w)
a  Shutdown the Redis server.  If Redis has persistence configured,
        data will be flushed before shutdown.
        It is possible to specify modifiers to alter the behavior of the command:
        ``save`` will force a DB saving operation even if no save points are configured.
        ``nosave`` will prevent a DB saving operation even if one or more save points
        are configured.
        ``now`` skips waiting for lagging replicas, i.e. it bypasses the first step in
        the shutdown sequence.
        ``force`` ignores any errors that would normally prevent the server from exiting
        ``abort`` cancels an ongoing shutdown and cannot be combined with other flags.

        For more information see https://redis.io/commands/shutdown
        +SHUTDOWN save and nosave cannot both be setSHUTDOWNr  NOSAVENOWFORCEABORTNSHUTDOWN seems to have failed.r   rQ   r1   r   r   r2   r  r  r  rj   r  r3   r:   s           r5   shutdownzManagementCommands.shutdown  s    , FIJJ|KKKK!KKKK KK 	 D  $1&1 9::  		s   3B 	BBc                 X    || | j                   di |S  | j                   d||fi |S )a  
        Set the server to be a replicated slave of the instance identified
        by the ``host`` and ``port``. If called without arguments, the
        instance is promoted to a master instead.

        For more information see https://redis.io/commands/slaveof
        )SLAVEOFr   s   ONEr  r0   )r2   rY  rZ  r3   s       r5   slaveofzManagementCommands.slaveof
  s?     <DL'4''KFKK#t##ItTDVDDr7   numc                     ddl m} dg}||j                  |       | j                         j	                  dd      }|du rg ||<    | j
                  |i |S )z
        Get the entries from the slowlog. If ``num`` is specified, get the
        most recent ``num`` items.

        For more information see https://redis.io/commands/slowlog-get
        r   r0  zSLOWLOG GETdecode_responsesFT)r5  r1  rQ   get_connection_kwargsgetr1   )r2   r  r3   r1  r:   r  s         r5   slowlog_getzManagementCommands.slowlog_get  sg     	.?KK557;;<NPUVt##%F< #t##T4V44r7   c                 &     | j                   di |S )z
        Get the number of items in the slowlog

        For more information see https://redis.io/commands/slowlog-len
        )zSLOWLOG LENr0   rH   s     r5   slowlog_lenzManagementCommands.slowlog_len)  s     $t##<V<<r7   c                 &     | j                   di |S )z{
        Remove all items in the slowlog

        For more information see https://redis.io/commands/slowlog-reset
        )zSLOWLOG RESETr0   rH   s     r5   slowlog_resetz ManagementCommands.slowlog_reset1       $t##>v>>r7   c                 &     | j                   di |S )z
        Returns the server time as a 2-item tuple of ints:
        (seconds since epoch, microseconds into this second).

        For more information see https://redis.io/commands/time
        )TIMEr0   rH   s     r5   timezManagementCommands.time9  r  r7   num_replicasc                 ,     | j                   d||fi |S )a  
        Redis synchronous replication
        That returns the number of replicas that processed the query when
        we finally have at least ``num_replicas``, or when the ``timeout`` was
        reached.

        For more information see https://redis.io/commands/wait
        WAITr0   )r2   r  r   r3   s       r5   waitzManagementCommands.waitB  s      $t##FL'LVLLr7   	num_localc                 .     | j                   d|||fi |S )a=  
        This command blocks the current client until all previous write
        commands by that client are acknowledged as having been fsynced
        to the AOF of the local Redis and/or at least the specified number
        of replicas.

        For more information see https://redis.io/commands/waitaof
        WAITAOFr0   )r2   r  r  r   r3   s        r5   waitaofzManagementCommands.waitaofM  s*     $t##y,
;A
 	
r7   c                     t        d      )r  z5HELLO is intentionally not implemented in the client.r   r   s    r5   hellozManagementCommands.hello\  s    
 "C
 	
r7   c                     t        d      )r  z8FAILOVER is intentionally not implemented in the client.r   r   s    r5   failoverzManagementCommands.failovere  s    
 "F
 	
r7   r~   )T)NNNNNNFr.   NNNN*)FFNFFFFFNN)^r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rA   r   r"   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r#   r  r  r  r  r  r  r!  r%  r+  r.  r8  r=  rB  rF  rJ  rM  rO  rR  floatrV  rc   r!   ra  re  rg  ri  rk  rn  rq  rs  ru  rx  rz  r}  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r7   r5   r   r     sP   ?S ?HSM ?>
At 
A 
A,i ,F3 FY F !%"&!%$(#'0D390D S$Y0D CI	0D
 dDj!0D T4Z 0D 0D 
0Dd=y = )-BD39%D9=j9ID	D6@) @A9 AE74='%.'&/IJE	E0;Y ; &*!#
T	"
 
 	

 
 
 
 

* &*!#
T	"
 
 	

 
 
 
 

* %)!#:@:@ T	":@ 	:@
 :@ :@ :@ :@ 
:@xEy EF3 FY FM3 Ms M M -255%)5	5 5C 5d 5	 52@) @=C =E)C.#2E,F =	=C 	=E)C.#2E,F 	=9

? ?
 !%"&!%	== 3-= #	=
 
=8FT#Y F4c4PS9n@U;V F
 #&LL.28nL	LPP P E$
*+,	P 
PBI B@) @8) 8C C9 C
=* =9 =AT A	 A@D @y @
7i 
7O3 O OGC G G9 G?C ?i ? +/JS$Y'J7;CyJ	J&:I :

	<uS%Z'8 	<y 	<-y - !%.
.
 .
 	.

 .
 .
 .
 .
 CI.
 
.
`
s 
 
I 


>	 >Ey E 6:JJ"'T	"2J	J$>	 >
>S >Y >6	 6>S >Y >6	 66	 6BI B6	 6 (;(; (; 	(;
 (; (; 
(;V GKE#t)$E38d3CE	E5uS$Y/ 5Y 5"=y =? ?6	 6	M 	Ms 	M 	M

,/
:=
	


r7   r   c                   p     e Zd Zd fdZd fdZd fdZd fdZ	 	 	 	 	 ddeded	ed
ededdfdZ xZ	S )AsyncManagementCommandsr.   Nc                 *   K   t        |   di |S wNr   superr   r2   r3   	__class__s     r5   r   z$AsyncManagementCommands.command_infos  s     w#-f--   c                 *   K   t        |   di |S wr  )r  r!  r  s     r5   r!  z&AsyncManagementCommands.debug_segfaultv  s     w%///r  c                 *   K   t        |   di |S wr  )r  rg  r  s     r5   rg  z%AsyncManagementCommands.memory_doctory  s     w$.v..r  c                 *   K   t        |   di |S wr  )r  ri  r  s     r5   ri  z#AsyncManagementCommands.memory_help|  s     w",V,,r  r  r  r  rj   r  c                 Z  K   |r|rt        d      dg}|r|j                  d       |r|j                  d       |r|j                  d       |r|j                  d       |r|j                  d       	  | j                  |i | d{    t	        d	      7 # t        $ r Y yw xY ww)
a  Shutdown the Redis server.  If Redis has persistence configured,
        data will be flushed before shutdown.  If the "save" option is set,
        a data flush will be attempted even if there is no persistence
        configured.  If the "nosave" option is set, no data flush will be
        attempted.  The "save" and "nosave" options cannot both be set.

        For more information see https://redis.io/commands/shutdown
        r  r  r  r  r  r  r  Nr  r  r  s           r5   r  z AsyncManagementCommands.shutdown  s     " FIJJ|KKKK!KKKK KK 	&$&&7777 9::	 8 		s<   A2B+5B 
BB B+B 	B(%B+'B((B+r  r  )
r   r   r   r   r!  rg  ri  r   r  __classcell__r  s   @r5   r  r  r  sg    .0/-
 #;#; #; 	#;
 #; #; 
#;r7   r  c                       e Zd ZdZ	 dded   dedeedf   fdZd Zd	efd
Z	 ddede	de
d	eedf   fdZdede	fdZdede	de
fdZed        ZdefdZy)BitFieldOperationz0
    Command builder for BITFIELD commands.
    Nclientr*   
AsyncRedisrw   default_overflowc                 j    || _         || _        || _        g | _        d| _        | j                          y )NWRAP)r  rw   _default_overflow
operations_last_overflowrc   )r2   r  rw   r  s       r5   __init__zBitFieldOperation.__init__  s2     !18:$

r7   c                 r    g | _         d| _        | j                  | j                  xs | j                         y)zL
        Reset the state of the instance to when it was constructed
        r  N)r  r  overflowr  r   s    r5   rc   zBitFieldOperation.reset  s0     $d,,C0C0CDr7   r  c                     |j                         }|| j                  k7  r$|| _        | j                  j                  d|f       | S )a  
        Update the overflow algorithm of successive INCRBY operations
        :param overflow: Overflow algorithm, one of WRAP, SAT, FAIL. See the
            Redis docs for descriptions of these algorithmsself.
        :returns: a :py:class:`BitFieldOperation` instance.
        OVERFLOW)upperr  r  rQ   )r2   r  s     r5   r  zBitFieldOperation.overflow  sB     >>#t***"*DOO""J#9:r7   fmtr:  	incrementc                 j    || j                  |       | j                  j                  d|||f       | S )a  
        Increment a bitfield by a given amount.
        :param fmt: format-string for the bitfield being updated, e.g. 'u8'
            for an unsigned 8-bit integer.
        :param offset: offset (in number of bits). If prefixed with a
            '#', this is an offset multiplier, e.g. given the arguments
            fmt='u8', offset='#2', the offset will be 16.
        :param int increment: value to increment the bitfield by.
        :param str overflow: overflow algorithm. Defaults to WRAP, but other
            acceptable values are SAT and FAIL. See the Redis docs for
            descriptions of these algorithms.
        :returns: a :py:class:`BitFieldOperation` instance.
        INCRBY)r  r  rQ   )r2   r  r:  r  r  s        r5   incrbyzBitFieldOperation.incrby  s6    ( MM(##vyABr7   c                 B    | j                   j                  d||f       | S )a  
        Get the value of a given bitfield.
        :param fmt: format-string for the bitfield being read, e.g. 'u8' for
            an unsigned 8-bit integer.
        :param offset: offset (in number of bits). If prefixed with a
            '#', this is an offset multiplier, e.g. given the arguments
            fmt='u8', offset='#2', the offset will be 16.
        :returns: a :py:class:`BitFieldOperation` instance.
        GETr  rQ   )r2   r  r:  s      r5   r  zBitFieldOperation.get  s"     	sF34r7   r   c                 D    | j                   j                  d|||f       | S )a  
        Set the value of a given bitfield.
        :param fmt: format-string for the bitfield being read, e.g. 'u8' for
            an unsigned 8-bit integer.
        :param offset: offset (in number of bits). If prefixed with a
            '#', this is an offset multiplier, e.g. given the arguments
            fmt='u8', offset='#2', the offset will be 16.
        :param int value: value to set at the given position.
        :returns: a :py:class:`BitFieldOperation` instance.
        SETr  )r2   r  r:  r   s       r5   setzBitFieldOperation.set  s$     	sFE:;r7   c                 f    d| j                   g}| j                  D ]  }|j                  |        |S )NBITFIELD)rw   r  r   )r2   rv   opss      r5   r   zBitFieldOperation.command  s3    488$?? 	CJJsO	
r7   r.   c                 l    | j                   }| j                           | j                  j                  | S )a#  
        Execute the operation(s) in a single BITFIELD command. The return value
        is a list of values corresponding to each operation. If the client
        used to create this instance was a pipeline, the list of values
        will be present within the pipeline's execute.
        )r   rc   r  r1   )r2   r   s     r5   executezBitFieldOperation.execute	  s-     ,,

*t{{**G44r7   r~   )r   r   r   r   r   r   r  rc   r  r   rA   r  r  r  propertyr   r   r  r   r7   r5   r  r    s     .2	+,   T	*	E $ &*   	
 T	"4s O s O C   	5 	5r7   r  c                      e Zd ZdZdededefdZ	 	 	 d}dedee	df   dee	df   d	e
e   def
d
Z	 d~ded   dedeedf   defdZ	 d~ded   dededede
e   defdZdedededefdZ	 	 	 d}dede	dee	df   dee	df   d	e
e   defdZ	 	 ddededeedf   dedef
dZddede	defd ZeZd!edefd"Zdefd#Zdedefd$Zd!edefd%ZeZ	 	 	 	 dded&ed'ed(ed)ed*edefd+Z	 	 	 	 dded,ed'ed(ed)ed*edefd-Z dede	fd.Z!dedefd/Z"dedefd0Z#	 	 	 	 	 dded1eedf   d2eedf   d3eedf   d4eedf   d5edefd6Z$defd7Z%dede	defd8Z&dede	de	defd9Z'dededefd:Z(ddede	defd;Z)e)Z*ddede+defd<Z,dd=e-defd>Z.	 dd?ed@edAededef
dBZ/	 	 dd?ed@edCe	dAededefdDZ0de1dEedefdFZ2dGe3e4ef   defdHZ5dGe3e4ef   defdIZ6dedJe	defdKZ7dedefdLZ8	 	 	 	 dded&ed'ed(ed)ed*edefdMZ9	 	 	 	 dded,ed'ed(ed)ed*edefdNZ:dede	fdOZ;dedPedefdQZ<dedefdRZ=	 ddedSe	dTedefdUZ>defdVZ?dAedWedefdXZ@dAedWefdYZA	 	 	 	 ddedZe+deded[ed\ee	df   d]ee	df   defd^ZB	 	 	 	 	 	 	 	 ddeded1eedf   d2eedf   d'ed(ed_ed`ed3eedf   d4eedf   defdaZCdedefdbZDdede	de	defdcZEded&ededefddZFdededefdeZGdede	dedefdfZH	 	 	 	 	 ddheIdi   djedkedleeIdg   eId   f   dmednedoee	df   dpedefdqZJdedefdrZKddede	de	defdsZLdEedefdtZMdedefduZNdedefdvZOd!eddfdwZPddxZQd!edefdyZR	 	 	 	 ddzed{edme
e   dne
e   doe
e	   dpe
e   deee	ef   fd|ZSy)BasicKeyCommandsz(
    Redis basic key-based commands
    rw   r   r.   c                 (    | j                  d||      S )a  
        Appends the string ``value`` to the value at ``key``. If ``key``
        doesn't already exist, create it with a value of ``value``.
        Returns the new length of the value at ``key``.

        For more information see https://redis.io/commands/append
        APPENDr0   )r2   rw   r   s      r5   rQ   zBasicKeyCommands.append  s     ##Hc599r7   Nstartendr   c                     |g}|%|#|j                  |       |j                  |       n||||t        d      ||j                  |        | j                  dg| S )z
        Returns the count of set bits in the value of ``key``.  Optional
        ``start`` and ``end`` parameters indicate which bytes to consider

        For more information see https://redis.io/commands/bitcount
        z$Both start and end must be specifiedBITCOUNTrQ   r   r1   )r2   rw   r  r  r   paramss         r5   bitcountzBasicKeyCommands.bitcount$  su     MM% MM#CKS_BCCMM$#t##J888r7   r2   r  r  c                     t        | ||      S )z
        Return a BitFieldOperation instance to conveniently construct one or
        more bitfield operations on ``key``.

        For more information see https://redis.io/commands/bitfield
        )r  )r  )r2   rw   r  s      r5   bitfieldzBasicKeyCommands.bitfield;  s     !s=MNNr7   encodingr:  itemsc                 |    |d||g}|xs g }|D ]  \  }}|j                  d||g         | j                  dg| S )a  
        Return an array of the specified bitfield values
        where the first value is found using ``encoding`` and ``offset``
        parameters and remaining values are result of corresponding
        encoding/offset pairs in optional list ``items``
        Read-only variant of the BITFIELD command.

        For more information see https://redis.io/commands/bitfield_ro
        r  BITFIELD_ROr   r1   )r2   rw   r  r:  r  r  s         r5   bitfield_rozBasicKeyCommands.bitfield_roH  sZ      uh/ % 	5HfMM5(F34	5#t##M;F;;r7   	operationdestr`   c                 ,     | j                   d||g| S )z
        Perform a bitwise operation using ``operation`` between ``keys`` and
        store the result in ``dest``.

        For more information see https://redis.io/commands/bitop
        BITOPr0   )r2   r  r  r`   s       r5   bitopzBasicKeyCommands.bitop_  s      $t##GYDtDDr7   bitc                     |dvrt        d      ||g}|duxr |j                  |       |||j                  |       n||t        d      ||j                  |        | j                  dg| S )a[  
        Return the position of the first bit set to 1 or 0 in a string.
        ``start`` and ``end`` defines search range. The range is interpreted
        as a range of bytes and not a range of bits, so start=0 and end=2
        means to look at the first three bytes.

        For more information see https://redis.io/commands/bitpos
        )r   r(   zbit must be 0 or 1Nz0start argument is not set, when end is specifiedBITPOSr   rQ   r1   )r2   rw   r	  r  r  r   r  s          r5   bitposzBasicKeyCommands.bitposh  s      f011sT2fmmE2MM#]sNOOMM$#t##H6v66r7   sourcedestinationr[  r]  c                     ||g}||j                  d|g       |r|j                  d        | j                  dg| S )a  
        Copy the value stored in the ``source`` key to the ``destination`` key.

        ``destination_db`` an alternative destination database. By default,
        the ``destination`` key is created in the source Redis database.

        ``replace`` whether the ``destination`` key should be removed before
        copying the value to it. By default, the value is not copied if
        the ``destination`` key already exists.

        For more information see https://redis.io/commands/copy
        DBREPLACECOPY)r   rQ   r1   )r2   r  r  r[  r]  r  s         r5   r\  zBasicKeyCommands.copy  sL    & +&%MM401MM)$#t##F4V44r7   r   amountc                 (    | j                  d||      S )z
        Decrements the value of ``key`` by ``amount``.  If no key exists,
        the value will be initialized as 0 - ``amount``

        For more information see https://redis.io/commands/decrby
        DECRBYr0   r2   r   r  s      r5   decrbyzBasicKeyCommands.decrby       ##HdF;;r7   namesc                 (     | j                   dg| S )z@
        Delete one or more keys specified by ``names``
        DELr0   r2   r  s     r5   deletezBasicKeyCommands.delete  s     $t##E2E22r7   c                 &    | j                  |       y r~   )r  r2   r   s     r5   __delitem__zBasicKeyCommands.__delitem__  s    Dr7   c                 D    ddl m} i }g ||<    | j                  d|fi |S )z
        Return a serialized version of the value stored at the specified key.
        If key does not exist a nil bulk reply is returned.

        For more information see https://redis.io/commands/dump
        r   r0  DUMPr4  )r2   r   r1  r7  s       r5   dumpzBasicKeyCommands.dump  s0     	. "#t##FD<G<<r7   c                 (     | j                   dg| S )z
        Returns the number of ``names`` that exist

        For more information see https://redis.io/commands/exists
        EXISTSr0   r  s     r5   existszBasicKeyCommands.exists       $t##H5u55r7   r  nxxxgtltc                 >   t        |t        j                        rt        |j	                               }t               }|r|j                  d       |r|j                  d       |r|j                  d       |r|j                  d        | j                  d||g| S )a;  
        Set an expire flag on key ``name`` for ``time`` seconds with given
        ``option``. ``time`` can be represented by an integer or a Python timedelta
        object.

        Valid options are:
            NX -> Set expiry only when the key has no expiry
            XX -> Set expiry only when the key has an existing expiry
            GT -> Set expiry only when the new expiry is greater than current one
            LT -> Set expiry only when the new expiry is less than current one

        For more information see https://redis.io/commands/expire
        NXXXGTLTEXPIRErP   datetime	timedeltarA   total_secondsr   rQ   r1   r2   r   r  r)  r*  r+  r,  
exp_options           r5   expirezBasicKeyCommands.expire  s    , dH../t))+,DV
d#d#d#d##t##HdDF:FFr7   whenc                 >   t        |t        j                        rt        |j                               }t	               }|r|j                  d       |r|j                  d       |r|j                  d       |r|j                  d        | j                  d||g| S )aH  
        Set an expire flag on key ``name`` with given ``option``. ``when``
        can be represented as an integer indicating unix time or a Python
        datetime object.

        Valid options are:
            -> NX -- Set expiry only when the key has no expiry
            -> XX -- Set expiry only when the key has an existing expiry
            -> GT -- Set expiry only when the new expiry is greater than current one
            -> LT -- Set expiry only when the new expiry is less than current one

        For more information see https://redis.io/commands/expireat
        r.  r/  r0  r1  EXPIREATrP   r4  rA   	timestampr   rQ   r1   r2   r   r:  r)  r*  r+  r,  r8  s           r5   expireatzBasicKeyCommands.expireat  s    , dH--.t~~'(DV
d#d#d#d##t##JdHZHHr7   c                 &    | j                  d|      S )z
        Returns the absolute Unix timestamp (since January 1, 1970) in seconds
        at which the given key will expire.

        For more information see https://redis.io/commands/expiretime
        
EXPIRETIMEr0   r2   rw   s     r5   
expiretimezBasicKeyCommands.expiretime  s     ##L#66r7   c                 &    | j                  d|      S )z
        Return the value at key ``name``, or None if the key doesn't exist

        For more information see https://redis.io/commands/get
        r  r0   r   s     r5   r  zBasicKeyCommands.get       ##E400r7   c                 &    | j                  d|      S )a-  
        Get the value at key ``name`` and delete the key. This command
        is similar to GET, except for the fact that it also deletes
        the key on success (if and only if the key's value type
        is a string).

        For more information see https://redis.io/commands/getdel
        GETDELr0   r   s     r5   getdelzBasicKeyCommands.getdel'  s     ##Hd33r7   expxexatpxatpersistc                 v   ||||h}t        |      dkD  st        |      dkD  r|rt        d      g }|U|j                  d       t        |t        j
                        rt        |j                               }|j                  |       |X|j                  d       t        |t        j
                        rt        |j                         dz        }|j                  |       |U|j                  d       t        |t        j                        rt        |j                               }|j                  |       |X|j                  d       t        |t        j                        rt        |j                         dz        }|j                  |       |r|j                  d	        | j                  d
|g| S )a  
        Get the value of key and optionally set its expiration.
        GETEX is similar to GET, but is a write command with
        additional options. All time parameters can be given as
        datetime.timedelta or integers.

        ``ex`` sets an expire flag on key ``name`` for ``ex`` seconds.

        ``px`` sets an expire flag on key ``name`` for ``px`` milliseconds.

        ``exat`` sets an expire flag on key ``name`` for ``ex`` seconds,
        specified in unix time.

        ``pxat`` sets an expire flag on key ``name`` for ``ex`` milliseconds,
        specified in unix time.

        ``persist`` remove the time to live associated with ``name``.

        For more information see https://redis.io/commands/getex
           r(   zK``ex``, ``px``, ``exat``, ``pxat``, and ``persist`` are mutually exclusive.EXPX  EXATPXATPERSISTGETEX)
r   r   rQ   rP   r4  r5  rA   r6  r>  r1   )	r2   r   rJ  rK  rL  rM  rN  opsetr4   s	            r5   getexzBasicKeyCommands.getex2  ss   < Rt$u:>SZ!^: 
 $&>MM$"h001))+,MM">MM$"h001))+d23MM"MM&!$ 1 124>>+,MM$MM&!$ 1 124>>+d23MM$MM)$#t##GT;F;;r7   c                 B    | j                  |      }||S t        |      )zg
        Return the value at key ``name``, raises a KeyError if the key
        doesn't exist.
        )r  KeyErrorr2   r   r   s      r5   __getitem__zBasicKeyCommands.__getitem__s  s&    
 Ltnr7   c                 (    | j                  d||      S )z
        Returns an integer indicating the value of ``offset`` in ``name``

        For more information see https://redis.io/commands/getbit
        GETBITr0   )r2   r   r:  s      r5   getbitzBasicKeyCommands.getbit}  s     ##HdF;;r7   c                 *    | j                  d|||      S )z
        Returns the substring of the string value stored at ``key``,
        determined by the offsets ``start`` and ``end`` (both are inclusive)

        For more information see https://redis.io/commands/getrange
        GETRANGEr0   )r2   rw   r  r  s       r5   getrangezBasicKeyCommands.getrange  s     ##JUC@@r7   c                 (    | j                  d||      S )a1  
        Sets the value at key ``name`` to ``value``
        and returns the old value at key ``name`` atomically.

        As per Redis 6.2, GETSET is considered deprecated.
        Please use SET with GET parameter in new code.

        For more information see https://redis.io/commands/getset
        GETSETr0   r\  s      r5   getsetzBasicKeyCommands.getset  s     ##HdE::r7   c                 (    | j                  d||      S )z
        Increments the value of ``key`` by ``amount``.  If no key exists,
        the value will be initialized as ``amount``

        For more information see https://redis.io/commands/incrby
        r  r0   r  s      r5   r  zBasicKeyCommands.incrby  r  r7   c                 (    | j                  d||      S )z
        Increments the value at key ``name`` by floating ``amount``.
        If no key exists, the value will be initialized as ``amount``

        For more information see https://redis.io/commands/incrbyfloat
        INCRBYFLOATr0   r  s      r5   incrbyfloatzBasicKeyCommands.incrbyfloat  s     ##M4@@r7   r  c                 *     | j                   d|fi |S )z~
        Returns a list of keys matching ``pattern``

        For more information see https://redis.io/commands/keys
        KEYSr0   r2   r  r3   s      r5   r`   zBasicKeyCommands.keys  s     $t##FG>v>>r7   
first_listsecond_listsrcc                 4    ||||g} | j                   dg| S )a  
        Atomically returns and removes the first/last element of a list,
        pushing it as the first/last element on the destination list.
        Returns the element being popped and pushed.

        For more information see https://redis.io/commands/lmove
        LMOVEr0   )r2   rn  ro  rp  r  r  s         r5   lmovezBasicKeyCommands.lmove  s*     k35#t##G5f55r7   r   c                 6    |||||g} | j                   dg| S )zo
        Blocking version of lmove.

        For more information see https://redis.io/commands/blmove
        BLMOVEr0   )r2   rn  ro  r   rp  r  r  s          r5   blmovezBasicKeyCommands.blmove  s,     k3g>#t##H6v66r7   r:   c                 d    ddl m} t        ||      }i }|sg ||<    | j                  dg|i |S )z
        Returns a list of values ordered identically to ``keys``

        For more information see https://redis.io/commands/mget
        r   )EMPTY_RESPONSEMGET)r5  rx  r)   r1   )r2   r`   r:   rx  r7  s        r5   mgetzBasicKeyCommands.mget  sB     	0D$'&(GN##t##F=T=W==r7   mappingc                 x    g }|j                         D ]  }|j                  |         | j                  dg| S )a
  
        Sets key/values based on a mapping. Mapping is a dictionary of
        key/value pairs. Both keys and values should be strings or types that
        can be cast to a string via str().

        For more information see https://redis.io/commands/mset
        MSETr  r   r1   r2   r{  r  pairs       r5   msetzBasicKeyCommands.mset  sB     MMO 	DLL	#t##F3U33r7   c                 x    g }|j                         D ]  }|j                  |         | j                  dg| S )av  
        Sets key/values based on a mapping if none of the keys are already set.
        Mapping is a dictionary of key/value pairs. Both keys and values
        should be strings or types that can be cast to a string via str().
        Returns a boolean indicating if the operation was successful.

        For more information see https://redis.io/commands/msetnx
        MSETNXr~  r  s       r5   msetnxzBasicKeyCommands.msetnx  sB     MMO 	DLL	#t##H5u55r7   dbc                 (    | j                  d||      S )z
        Moves the key ``name`` to a different Redis database ``db``

        For more information see https://redis.io/commands/move
        MOVEr0   )r2   r   r  s      r5   movezBasicKeyCommands.move  s     ##FD"55r7   c                 &    | j                  d|      S )zw
        Removes an expiration on ``name``

        For more information see https://redis.io/commands/persist
        rV  r0   r   s     r5   rN  zBasicKeyCommands.persist       ##It44r7   c                 D   t        |t        j                        rt        |j	                         dz        }t               }|r|j                  d       |r|j                  d       |r|j                  d       |r|j                  d        | j                  d||g| S )aA  
        Set an expire flag on key ``name`` for ``time`` milliseconds
        with given ``option``. ``time`` can be represented by an
        integer or a Python timedelta object.

        Valid options are:
            NX -> Set expiry only when the key has no expiry
            XX -> Set expiry only when the key has an existing expiry
            GT -> Set expiry only when the new expiry is greater than current one
            LT -> Set expiry only when the new expiry is less than current one

        For more information see https://redis.io/commands/pexpire
        rS  r.  r/  r0  r1  PEXPIREr3  r7  s           r5   pexpirezBasicKeyCommands.pexpire  s    , dH../t))+d23DV
d#d#d#d##t##ItTGJGGr7   c                 D   t        |t        j                        rt        |j                         dz        }t	               }|r|j                  d       |r|j                  d       |r|j                  d       |r|j                  d        | j                  d||g| S )ab  
        Set an expire flag on key ``name`` with given ``option``. ``when``
        can be represented as an integer representing unix time in
        milliseconds (unix time * 1000) or a Python datetime object.

        Valid options are:
            NX -> Set expiry only when the key has no expiry
            XX -> Set expiry only when the key has an existing expiry
            GT -> Set expiry only when the new expiry is greater than current one
            LT -> Set expiry only when the new expiry is less than current one

        For more information see https://redis.io/commands/pexpireat
        rS  r.  r/  r0  r1  	PEXPIREATr=  r?  s           r5   	pexpireatzBasicKeyCommands.pexpireat0  s    , dH--.t~~'$./DV
d#d#d#d##t##KtIjIIr7   c                 &    | j                  d|      S )z
        Returns the absolute Unix timestamp (since January 1, 1970) in milliseconds
        at which the given key will expire.

        For more information see https://redis.io/commands/pexpiretime
        PEXPIRETIMEr0   rC  s     r5   pexpiretimezBasicKeyCommands.pexpiretimeS  s     ##M377r7   time_msc                     t        |t        j                        rt        |j	                         dz        }| j                  d|||      S )a  
        Set the value of key ``name`` to ``value`` that expires in ``time_ms``
        milliseconds. ``time_ms`` can be represented by an integer or a Python
        timedelta object

        For more information see https://redis.io/commands/psetex
        rS  PSETEXrP   r4  r5  rA   r6  r1   )r2   r   r  r   s       r5   psetexzBasicKeyCommands.psetex\  sC     gx112'//1D89G##HdGUCCr7   c                 &    | j                  d|      S )z
        Returns the number of milliseconds until the key ``name`` will expire

        For more information see https://redis.io/commands/pttl
        PTTLr0   r   s     r5   pttlzBasicKeyCommands.pttlh       ##FD11r7   rM   
withvaluesc                 z    g }||j                  |       |r|j                  d        | j                  d|g| S )ap  
        Return a random field from the hash value stored at key.

        count: if the argument is positive, return an array of distinct fields.
        If called with a negative count, the behavior changes and the command
        is allowed to return the same field multiple times. In this case,
        the number of returned fields is the absolute value of the
        specified count.
        withvalues: The optional WITHVALUES modifier changes the reply so it
        includes the respective values of the randomly selected hash fields.

        For more information see https://redis.io/commands/hrandfield
        
WITHVALUES
HRANDFIELDr   )r2   rw   rM   r  r  s        r5   
hrandfieldzBasicKeyCommands.hrandfieldp  sD      MM% MM,'#t##L#???r7   c                 &     | j                   di |S )zx
        Returns the name of a random key

        For more information see https://redis.io/commands/randomkey
        )	RANDOMKEYr0   rH   s     r5   	randomkeyzBasicKeyCommands.randomkey  r   r7   dstc                 (    | j                  d||      S )zr
        Rename key ``src`` to ``dst``

        For more information see https://redis.io/commands/rename
        RENAMEr0   r2   rp  r  s      r5   renamezBasicKeyCommands.rename  s     ##Hc377r7   c                 (    | j                  d||      S )z
        Rename key ``src`` to ``dst`` if ``dst`` doesn't already exist

        For more information see https://redis.io/commands/renamenx
        RENAMENXr0   r  s      r5   renamenxzBasicKeyCommands.renamenx  s     ##JS99r7   ttlabsttlidletime	frequencyc                    |||g}|r|j                  d       |r|j                  d       |,|j                  d       	 |j                  t        |             |,|j                  d       	 |j                  t        |              | j                  dg| S # t        $ r t        d      w xY w# t        $ r t        d      w xY w)a  
        Create a key using the provided serialized value, previously obtained
        using DUMP.

        ``replace`` allows an existing key on ``name`` to be overridden. If
        it's not specified an error is raised on collision.

        ``absttl`` if True, specified ``ttl`` should represent an absolute Unix
        timestamp in milliseconds in which the key will expire. (Redis 5.0 or
        greater).

        ``idletime`` Used for eviction, this is the number of seconds the
        key must be idle, prior to execution.

        ``frequency`` Used for eviction, this is the frequency counter of
        the object stored at the key, prior to execution.

        For more information see https://redis.io/commands/restore
        r  ABSTTLIDLETIMEzidletimemust be an integerFREQzfrequency must be an integerRESTORE)rQ   rA   rB   r   r1   )	r2   r   r  r   r]  r  r  r  r  s	            r5   restorezBasicKeyCommands.restore  s    : U#MM)$MM(#MM*%>c(m,  MM&!@c)n- $t##I777  > <==>  @ >??@s    B .B3 B03Ckeepttlr  c                    ||g}i }||j                  d       t        |t        j                        r)|j                  t	        |j                                      nht        |t              r|j                  |       nFt        |t              r+|j                         r|j                  t	        |             nt        d      ||j                  d       t        |t        j                        r,|j                  t	        |j                         dz               n-t        |t              r|j                  |       nt        d      |	U|j                  d       t        |	t        j                        rt	        |	j                               }	|j                  |	       |
X|j                  d       t        |
t        j                        rt	        |
j                         dz        }
|j                  |
       |r|j                  d       |r|j                  d	       |r|j                  d
       |r|j                  d       d|d<    | j                  dg|i |S )a  
        Set the value at key ``name`` to ``value``

        ``ex`` sets an expire flag on key ``name`` for ``ex`` seconds.

        ``px`` sets an expire flag on key ``name`` for ``px`` milliseconds.

        ``nx`` if set to True, set the value at key ``name`` to ``value`` only
            if it does not exist.

        ``xx`` if set to True, set the value at key ``name`` to ``value`` only
            if it already exists.

        ``keepttl`` if True, retain the time to live associated with the key.
            (Available since Redis 6.0)

        ``get`` if True, set the value at key ``name`` to ``value`` and return
            the old value stored at key, or None if the key did not exist.
            (Available since Redis 6.2)

        ``exat`` sets an expire flag on key ``name`` for ``ex`` seconds,
            specified in unix time.

        ``pxat`` sets an expire flag on key ``name`` for ``ex`` milliseconds,
            specified in unix time.

        For more information see https://redis.io/commands/set
        rQ  z$ex must be datetime.timedelta or intrR  rS  z$px must be datetime.timedelta or intrT  rU  KEEPTTLr.  r/  r  Tr  r  )rQ   rP   r4  r5  rA   r6  r   isdigitr   r>  r1   )r2   r   r   rJ  rK  r)  r*  r  r  rL  rM  r4   r7  s                r5   r  zBasicKeyCommands.set  s   R %)%=>MM$"h001c""2"2"456B$b!B$c"g& FGG>MM$"h001c""2"2"4t";<=B$b! FGGMM&!$ 1 124>>+,MM$MM&!$ 1 124>>+d23MM$MM)$MM$MM$MM% !GEN#t##E>F>g>>r7   c                 (    | j                  ||       y r~   )r  r\  s      r5   __setitem__zBasicKeyCommands.__setitem__'	  s    ur7   c                 >    |xr dxs d}| j                  d|||      S )z
        Flag the ``offset`` in ``name`` as ``value``. Returns an integer
        indicating the previous value of ``offset``.

        For more information see https://redis.io/commands/setbit
        r(   r   SETBITr0   r2   r   r:  r   s       r5   setbitzBasicKeyCommands.setbit*	  s)     ! q##HdFEBBr7   c                     t        |t        j                        rt        |j	                               }| j                  d|||      S )z
        Set the value of key ``name`` to ``value`` that expires in ``time``
        seconds. ``time`` can be represented by an integer or a Python
        timedelta object.

        For more information see https://redis.io/commands/setex
        SETEXr  )r2   r   r  r   s       r5   setexzBasicKeyCommands.setex4	  s>     dH../t))+,D##GT4??r7   c                 (    | j                  d||      S )z
        Set the value of key ``name`` to ``value`` if key doesn't exist

        For more information see https://redis.io/commands/setnx
        SETNXr0   r\  s      r5   setnxzBasicKeyCommands.setnx@	  s     ##GT599r7   c                 *    | j                  d|||      S )a!  
        Overwrite bytes in the value of ``name`` starting at ``offset`` with
        ``value``. If ``offset`` plus the length of ``value`` exceeds the
        length of the original value, the new value will be larger than before.
        If ``offset`` exceeds the length of the original value, null bytes
        will be used to pad between the end of the previous value and the start
        of what's being injected.

        Returns the length of the new string.

        For more information see https://redis.io/commands/setrange
        SETRANGEr0   r  s       r5   setrangezBasicKeyCommands.setrangeH	  s     ##JfeDDr7   stringsalgoLCSvalue1value2specific_argumentr   idxminmatchlenwithmatchlenc	                    dg}
||
vrdj                  |
      }t        d|       |dvrt        d      |r|rt        d      ||j                         ||g}|r|j                  d       |r|j                  d       	 t	        |       |j                  d	|g       |r|j                  d
        | j                  dg|||||d|	S # t        $ r Y 9w xY w)a  
        Implements complex algorithms that operate on strings.
        Right now the only algorithm implemented is the LCS algorithm
        (longest common substring). However new algorithms could be
        implemented in the future.

        ``algo`` Right now must be LCS
        ``value1`` and ``value2`` Can be two strings or two keys
        ``specific_argument`` Specifying if the arguments to the algorithm
        will be keys or strings. strings is the default.
        ``len`` Returns just the len of the match.
        ``idx`` Returns the match positions in each string.
        ``minmatchlen`` Restrict the list of matches to the ones of a given
        minimal length. Can be provided only when ``idx`` set to True.
        ``withmatchlen`` Returns the matches with the len of the match.
        Can be provided only when ``idx`` set to True.

        For more information see https://redis.io/commands/stralgo
        r  z, zThe supported algorithms are: )r`   r  z-specific_argument can be only keys or stringsz(len and idx cannot be provided together.s   LENs   IDXs   MINMATCHLENs   WITHMATCHLENSTRALGO)r   r  r  r  )r   r   r  rQ   rA   r   	TypeErrorr1   )r2   r  r  r  r  r   r  r  r  r3   supported_algosupported_algos_strr4   s                r5   stralgozBasicKeyCommands.stralgoW	  s   @  ~%"&))N";<=P<QRSS$77KLL3FGG$(*;*A*A*CVV#TMM&!MM&!	MM>;78 MM/*#t##

 #%
 
 	
  		s    C 	CCc                 &    | j                  d|      S )z
        Return the number of bytes stored in the value of ``name``

        For more information see https://redis.io/commands/strlen
        STRLENr0   r   s     r5   strlenzBasicKeyCommands.strlen	  s     ##Hd33r7   c                 *    | j                  d|||      S )z
        Return a substring of the string at key ``name``. ``start`` and ``end``
        are 0-based integers specifying the portion of the string to return.
        SUBSTRr0   r2   r   r  r  s       r5   substrzBasicKeyCommands.substr	  s    
 ##HdE3??r7   c                 (     | j                   dg| S )z
        Alters the last access time of a key(s) ``*args``. A key is ignored
        if it does not exist.

        For more information see https://redis.io/commands/touch
        TOUCHr0   r  s     r5   touchzBasicKeyCommands.touch	  s     $t##G3d33r7   c                 &    | j                  d|      S )z
        Returns the number of seconds until the key ``name`` will expire

        For more information see https://redis.io/commands/ttl
        TTLr0   r   s     r5   r  zBasicKeyCommands.ttl	  rF  r7   c                 &    | j                  d|      S )zs
        Returns the type of key ``name``

        For more information see https://redis.io/commands/type
        TYPEr0   r   s     r5   typezBasicKeyCommands.type	  r  r7   c                 @    t        j                  t        d             y)z
        Watches the values at keys ``names``, or None if the key doesn't exist

        For more information see https://redis.io/commands/watch
        z!Call WATCH from a Pipeline objectNwarningswarnDeprecationWarningr  s     r5   watchzBasicKeyCommands.watch	  s     	()LMNr7   c                 @    t        j                  t        d             y)z
        Unwatches the value at key ``name``, or None of the key doesn't exist

        For more information see https://redis.io/commands/unwatch
        z#Call UNWATCH from a Pipeline objectNr  r   s    r5   unwatchzBasicKeyCommands.unwatch	  s     	()NOPr7   c                 (     | j                   dg| S )z
        Unlink one or more keys specified by ``names``

        For more information see https://redis.io/commands/unlink
        UNLINKr0   r  s     r5   unlinkzBasicKeyCommands.unlink	  r(  r7   key1key2c                     ||g}|r|j                  d       |r|j                  d       |dk7  r|j                  d|g       |r|j                  d        | j                  dg| S )a  
        Find the longest common subsequence between ``key1`` and ``key2``.
        If ``len`` is true the length of the match will will be returned.
        If ``idx`` is true the match position in each strings will be returned.
        ``minmatchlen`` restrict the list of matches to the ones of
        the given ``minmatchlen``.
        If ``withmatchlen`` the length of the match also will be returned.
        For more information see https://redis.io/commands/lcs
        LENIDXr   MINMATCHLENWITHMATCHLENr  rQ   r   r1   )r2   r  r  r   r  r  r  r4   s           r5   lcszBasicKeyCommands.lcs	  sk    $ MM% MM% !MM=+67MM.)#t##E3F33r7   r  r~   NFr(   )FFFF)NNNNFg      ?r  )LEFTRIGHT)FFNN)NNFFFFNN)r  FFNF)r  )FFr   F)Tr   r   r   r   r"   r   r   rQ   r   rA   r   r   r  r  r  r   r   r  r  r  r   r\  r  decrr  r!  r$  r'  __contains__r   r9  r   r@  rD  r  rI  rY  r]  r`  rc  rf  r  incrr  rj  r#   r`   rs  rv  r!   rz  r   r   r  r  r  rN  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r  r  r  r  r  r  r  r  r  r  r   r7   r5   r  r    sO
   :$ :z :i : #' $"99 S$Y9 39	9
 sm9 
94 .2O)*OO  T	*O 
	O$ !%<)*<< <  	<
 ~< 
<.Es E$ Et E	 E #' $"77 7 S$Y	7
 397 sm7 
7F ,055 5 c4i(	5
 5 
54<4 < <Y < D3T 3i 3 = =) =6T 6i 6 L #G#G #G 	#G
 #G #G #G 
#GR #I#I #I 	#I
 #I #I #I 
#IJ7c 7c 71 1 1	44 	4I 	4 $(#'(,(,?<?< '4- ?< '4- 	?<
 J$%?< J$%?< ?< 
?<B <4 < < <AD A A3 A9 A
;4 
;
 
;y 
;<4 < <Y < DA Ae Ai A?H ? ? QX66,/6696JM6	6$ 77 7 	7
 7 7 
7 > >z >i >4GGZ$78 4Y 46ggz&9: 6y 66 63 69 65D 5Y 5 "H"H "H 	"H
 "H "H "H 
"HP !J!J !J 	!J
 !J !J !J 
!JF8s 8s 8
D4 
D' 
D* 
D2 2) 2 ?D@@"@7;@	@0;Y ;8$ 8T 8i 8:D :t : %)&*0808 08 	08
 08 08 T	"08 d#08 
08l $(#'(,(,S?S? S? '4- 	S?
 '4- S? S? S? S? S? J$%S? J$%S? 
S?j Z C4 C CS CY C
@$ 
@g 
@j 
@Y 
@:$ :z :i :ET E3 Ez Ei E( IR(,">
en>
 >
 	>

 !!3WV_!DE>
 >
 >
 39%>
 >
 
>
@44 4I 4@4 @ @# @y @44 4I 41 1 12 2) 2OD OT OQ6T 6i 6 $#%&',44 4 d^	4
 d^4 c]4 tn4 
sC~	4r7   r  c                   h     e Zd ZdefdZdefdZdefdZdedefdZdedd	f fd
Z	d fdZ
 xZS )AsyncBasicKeyCommandsr   c                     t        d      )Nz2Async Redis client does not support class deletionr  r   s     r5   r!  z!AsyncBasicKeyCommands.__delitem__	  s    LMMr7   c                     t        d      )Nz3Async Redis client does not support class inclusionr  r   s     r5   r  z"AsyncBasicKeyCommands.__contains__	      MNNr7   c                     t        d      )Nz3Async Redis client does not support class retrievalr  r   s     r5   r]  z!AsyncBasicKeyCommands.__getitem__	  r
  r7   r   c                     t        d      )Nz4Async Redis client does not support class assignmentr  r\  s      r5   r  z!AsyncBasicKeyCommands.__setitem__	  s    NOOr7   r  r.   Nc                 $   K   t        |   | S wr~   )r  r  )r2   r  r  s     r5   r  zAsyncBasicKeyCommands.watch
  s     w}e$$s   c                 (   K   t         |          S wr~   )r  r  r2   r  s    r5   r  zAsyncBasicKeyCommands.unwatch
  s     w     r  )r   r   r   r"   r!  r  r]  r   r  r  r  r  r  s   @r5   r  r  	  s`    N NO OO OP PZ P%$ %4 %! !r7   r  c                      e Zd ZdZ	 d7dedee   deee	   e	f   fdZ
	 d7dedee   deee	   e	f   fdZ	 d7dededee   deeee      ee   f   fd	Zd
ddededee   dedee   dee	   fdZd
ddedee   dedee   deee	   e	f   f
dZdededeeee      ee   f   fdZdededededeee   ef   f
dZdedeee   ef   fdZ	 d8dedee   deeeeedf      eeedf   f   fdZdededeee   ef   fdZdededeee   ef   fdZded ed!edeee	   e	f   fd"Zdedededeee   ef   fd#Zdedededeee   ef   fd$Zded ed!edeee   ef   fd%Z	 d8dedee   deeeeedf      eeedf   f   fd&Zdededeee   ef   fd'Zdededeee   ef   fd(Zdededeee   ef   fd)Z	 	 	 d9deded*ee   dee   d+ee   deeedf   fd,Z 	 	 	 	 	 	 	 	 d:ded ee   d-ee   d.ee   d/eee      d0e!d1e!d2ee   d3ee!   deeef   fd4Z"	 	 	 	 	 	 d;d5ed ee   d-ee   d.ee   d/eee      d0e!d1e!de	fd6Z#y)<ListCommandsz^
    Redis commands for List data type.
    see: https://redis.io/topics/data-types#lists
    r`   r   r.   c                 j    |d}t        |d      }|j                  |        | j                  dg| S )a  
        LPOP a value off of the first non-empty list
        named in the ``keys`` list.

        If none of the lists in ``keys`` has a value to LPOP, then block
        for ``timeout`` seconds, or until a value gets pushed on to one
        of the lists.

        If timeout is 0, then block indefinitely.

        For more information see https://redis.io/commands/blpop
        Nr   BLPOPr)   rQ   r1   r2   r`   r   s      r5   blpopzListCommands.blpop
  >     ?GD$'G#t##G3d33r7   c                 j    |d}t        |d      }|j                  |        | j                  dg| S )a  
        RPOP a value off of the first non-empty list
        named in the ``keys`` list.

        If none of the lists in ``keys`` has a value to RPOP, then block
        for ``timeout`` seconds, or until a value gets pushed on to one
        of the lists.

        If timeout is 0, then block indefinitely.

        For more information see https://redis.io/commands/brpop
        Nr   BRPOPr  r  s      r5   brpopzListCommands.brpop$
  r  r7   rp  r  c                 2    |d}| j                  d|||      S )ac  
        Pop a value off the tail of ``src``, push it on the head of ``dst``
        and then return it.

        This command blocks until a value is in ``src`` or until ``timeout``
        seconds elapse, whichever is first. A ``timeout`` value of 0 blocks
        forever.

        For more information see https://redis.io/commands/brpoplpush
        r   
BRPOPLPUSHr0   )r2   rp  r  r   s       r5   
brpoplpushzListCommands.brpoplpush9
  s%     ?G##L#sGDDr7   r(   )rM   numkeysr:   	directionrM   c                @    ||g||d|} | j                   dg| S )a[  
        Pop ``count`` values (default 1) from first non-empty in the list
        of provided key names.

        When all lists are empty this command blocks the connection until another
        client pushes to it or until the timeout, timeout of 0 blocks indefinitely

        For more information see https://redis.io/commands/blmpop
        COUNTBLMPOPr0   )r2   r   r  r   rM   r:   s         r5   blmpopzListCommands.blmpopJ
  s:    " C4CCGCUC#t##H4t44r7   num_keysc                ~    |gt        |      z   |gz   }|dk7  r|j                  d|g        | j                  dg| S )z
        Pop ``count`` values (default 1) first non-empty list key from the list
        of args provided key names.

        For more information see https://redis.io/commands/lmpop
        r(   r"  LMPOP)r   r   r1   )r2   r%  r   rM   r:   s        r5   lmpopzListCommands.lmpop_
  sK     zDJ&)4A:KK%()#t##G3d33r7   r   rC  c                 (    | j                  d||      S )z
        Return the item from list ``name`` at position ``index``

        Negative indexes are supported and will return an item at the
        end of the list

        For more information see https://redis.io/commands/lindex
        LINDEXr0   )r2   r   rC  s      r5   lindexzListCommands.lindexr
  s     ##HdE::r7   whererefvaluer   c                 ,    | j                  d||||      S )a$  
        Insert ``value`` in list ``name`` either immediately before or after
        [``where``] ``refvalue``

        Returns the new length of the list on success or -1 if ``refvalue``
        is not in the list.

        For more information see https://redis.io/commands/linsert
        LINSERTr0   )r2   r   r,  r-  r   s        r5   linsertzListCommands.linsert
  s     ##ItUHeLLr7   c                 &    | j                  d|      S )zy
        Return the length of the list ``name``

        For more information see https://redis.io/commands/llen
        LLENr0   r   s     r5   llenzListCommands.llen
  r  r7   Nc                 P    || j                  d||      S | j                  d|      S )az  
        Removes and returns the first elements of the list ``name``.

        By default, the command pops a single element from the beginning of
        the list. When provided with the optional ``count`` argument, the reply
        will consist of up to count elements, depending on the list's length.

        For more information see https://redis.io/commands/lpop
        LPOPr0   r2   r   rM   s      r5   lpopzListCommands.lpop
  2     ''e<<''55r7   valuesc                 *     | j                   d|g| S )z
        Push ``values`` onto the head of the list ``name``

        For more information see https://redis.io/commands/lpush
        LPUSHr0   r2   r   r9  s      r5   lpushzListCommands.lpush
       $t##GT;F;;r7   c                 *     | j                   d|g| S )z
        Push ``value`` onto the head of the list ``name`` if ``name`` exists

        For more information see https://redis.io/commands/lpushx
        LPUSHXr0   r<  s      r5   lpushxzListCommands.lpushx
       $t##Hd<V<<r7   r  r  c                 *    | j                  d|||      S )a  
        Return a slice of the list ``name`` between
        position ``start`` and ``end``

        ``start`` and ``end`` can be negative numbers just like
        Python slicing notation

        For more information see https://redis.io/commands/lrange
        LRANGEr0   r  s       r5   lrangezListCommands.lrange
  s     ##HdE3??r7   c                 *    | j                  d|||      S )a  
        Remove the first ``count`` occurrences of elements equal to ``value``
        from the list stored at ``name``.

        The count argument influences the operation in the following ways:
            count > 0: Remove elements equal to value moving from head to tail.
            count < 0: Remove elements equal to value moving from tail to head.
            count = 0: Remove all elements equal to value.

            For more information see https://redis.io/commands/lrem
        LREMr0   )r2   r   rM   r   s       r5   lremzListCommands.lrem
  s     ##FD%??r7   c                 *    | j                  d|||      S )z
        Set element at ``index`` of list ``name`` to ``value``

        For more information see https://redis.io/commands/lset
        LSETr0   )r2   r   rC  r   s       r5   lsetzListCommands.lset
  s     ##FD%??r7   c                 *    | j                  d|||      S )a  
        Trim the list ``name``, removing all values not within the slice
        between ``start`` and ``end``

        ``start`` and ``end`` can be negative numbers just like
        Python slicing notation

        For more information see https://redis.io/commands/ltrim
        LTRIMr0   r  s       r5   ltrimzListCommands.ltrim
  s     ##GT5#>>r7   c                 P    || j                  d||      S | j                  d|      S )as  
        Removes and returns the last elements of the list ``name``.

        By default, the command pops a single element from the end of the list.
        When provided with the optional ``count`` argument, the reply will
        consist of up to count elements, depending on the list's length.

        For more information see https://redis.io/commands/rpop
        RPOPr0   r6  s      r5   rpopzListCommands.rpop
  r8  r7   c                 (    | j                  d||      S )z
        RPOP a value off of the ``src`` list and atomically LPUSH it
        on to the ``dst`` list.  Returns the value.

        For more information see https://redis.io/commands/rpoplpush
        	RPOPLPUSHr0   r  s      r5   	rpoplpushzListCommands.rpoplpush
  s     ##Kc::r7   c                 *     | j                   d|g| S )z
        Push ``values`` onto the tail of the list ``name``

        For more information see https://redis.io/commands/rpush
        RPUSHr0   r<  s      r5   rpushzListCommands.rpush  r>  r7   c                 *     | j                   d|g| S )z
        Push ``value`` onto the tail of the list ``name`` if ``name`` exists

        For more information see https://redis.io/commands/rpushx
        RPUSHXr0   r<  s      r5   rpushxzListCommands.rpushx
  rB  r7   rankmaxlenc                     ||g}||j                  d|g       ||j                  d|g       ||j                  d|g        | j                  dg| S )ab  
        Get position of ``value`` within the list ``name``

         If specified, ``rank`` indicates the "rank" of the first element to
         return in case there are multiple copies of ``value`` in the list.
         By default, LPOS returns the position of the first occurrence of
         ``value`` in the list. When ``rank`` 2, LPOS returns the position of
         the second ``value`` in the list. If ``rank`` is negative, LPOS
         searches the list in reverse. For example, -1 would return the
         position of the last occurrence of ``value`` and -2 would return the
         position of the next to last occurrence of ``value``.

         If specified, ``count`` indicates that LPOS should return a list of
         up to ``count`` positions. A ``count`` of 2 would return a list of
         up to 2 positions. A ``count`` of 0 returns a list of all positions
         matching ``value``. When ``count`` is specified and but ``value``
         does not exist in the list, an empty list is returned.

         If specified, ``maxlen`` indicates the maximum number of list
         elements to scan. A ``maxlen`` of 1000 will only return the
         position(s) of items within the first 1000 entries in the list.
         A ``maxlen`` of 0 (the default) will scan the entire list.

         For more information see https://redis.io/commands/lpos
        RANKr"  MAXLENLPOSr  )r2   r   r   r[  rM   r\  r4   s          r5   lposzListCommands.lpos  sj    B %)%=MM64.)MM7E*+MM8V,-#t##F4V44r7   r  byr  descalphastoregroupsc
                 >   ||||t        d      |g}
||
j                  d|g       |||
j                  d||g       |Dt        |t        t        f      r|
j                  d|g       n|D ]  }|
j                  d|g        |r|
j                  d       |r|
j                  d       ||
j                  d|g       |	r1|r$t        |t        t        f      st        |      d	k  rt        d
      d|	rt        |      ndi} | j                  dg|
i |S )a  
        Sort and return the list, set or sorted set at ``name``.

        ``start`` and ``num`` allow for paging through the sorted data

        ``by`` allows using an external key to weight and sort the items.
            Use an "*" to indicate where in the key the item value is located

        ``get`` allows for returning items from external keys rather than the
            sorted data itself.  Use an "*" to indicate where in the key
            the item value is located

        ``desc`` allows for reversing the sort

        ``alpha`` allows for sorting lexicographically rather than numerically

        ``store`` allows for storing the result of the sort into
            the key ``store``

        ``groups`` if set to True and if ``get`` contains at least two
            elements, sort will return a list of tuples, each containing the
            values fetched from the arguments to ``get``.

        For more information see https://redis.io/commands/sort
        N,``start`` and ``num`` must both be specifieds   BY   LIMITs   GET   DESCs   ALPHA   STORErP  zVwhen using "groups" the "get" argument must be specified and contain at least two keysrf  SORT)r   r   rP   bytesr   rQ   r   r1   )r2   r   r  r  rb  r  rc  rd  re  rf  r4   gr7  s                r5   sortzListCommands.sort?  s5   J #+3?u}JKK$(6>MM5"+&MM8UC01?
 #s|,vsm, /AMM61+./MM'"MM(#MM8U+,*S5#,73s8a<  SXT:#t##F?V?w??r7   rw   c           	      2    | j                  |||||||      S )a  
        Returns the elements contained in the list, set or sorted set at key.
        (read-only variant of the SORT command)

        ``start`` and ``num`` allow for paging through the sorted data

        ``by`` allows using an external key to weight and sort the items.
            Use an "*" to indicate where in the key the item value is located

        ``get`` allows for returning items from external keys rather than the
            sorted data itself.  Use an "*" to indicate where in the key
            the item value is located

        ``desc`` allows for reversing the sort

        ``alpha`` allows for sorting lexicographically rather than numerically

        For more information see https://redis.io/commands/sort_ro
        )r  r  rb  r  rc  rd  )ro  )r2   rw   r  r  rb  r  rc  rd  s           r5   sort_rozListCommands.sort_ro  s)    : yyu#"#D  
 	
r7   r   r~   r  )NNNNFFNF)NNNNFF)$r   r   r   r   r   r   rA   r   r   r   r  r  r   r  r  r$  r(  r+  r0  r3  r7  r   r=  rA  rE  rH  rK  rN  rQ  rT  rW  rZ  ra  r   ro  rq  r   r7   r5   r  r  	
  s    4544#+C=4	y$	%4, 4544#+C=4	y$	%4, <=EE E+3C=E	y#'#6	7E.  !55 5 Cy	5
 5 }5 
$54  !44 Cy4 	4
 }4 
y$	%4&;; #;	y#'#6	7;MM #M/2M;>M	y~s"	#M2 2y~s':!; 2  $66 }6 
ysD$/0%T42HH	I	6&<# < <539L3M <=3 = =E)C.#:M4N =
@3 
@s 
@ 
@yPT?T9U 
@@ @S @ @y~s?R9S @@ @S @ @y~s?R9S @
?# 
?c 
? 
?inc>Q8R 
?  $66 }6 
ysD$/0%T42HH	I	6&;S ;s ;uYs^S5H/I ;<# < <539L3M <=3 = =y~s7J1K = ## $+5+5 +5 sm	+5
 }+5 +5 
sD$	+5`  $! #'#!&F@F@ }F@ c]	F@
 SMF@ d3i F@ F@ F@ }F@ F@ 
tSy	F@V  $! #'

 }
 c]	

 SM
 d3i 
 
 
 

r7   r  c                      e Zd ZdZ	 	 	 	 ddedeedf   deedf   deedf   def
d	Z		 	 	 ddeedf   deedf   deedf   de
fd
Z	 	 	 ddededeedf   deedf   def
dZ	 	 ddedeedf   deedf   de
fdZ	 	 	 ddededeedf   deedf   def
dZ	 	 ddedeedf   deedf   de
fdZdddefdededeedf   deedf   deeef   defdZddefdedeedf   deedf   deeef   de
f
dZy)ScanCommandszF
    Redis SCAN commands.
    see: https://redis.io/commands/scan
    r   NcursormatchrM   r   r.   c                     |g}||j                  d|g       ||j                  d|g       ||j                  d|g        | j                  dg|i |S )a^  
        Incrementally return lists of key names. Also return a cursor
        indicating the scan position.

        ``match`` allows for filtering the keys by pattern

        ``count`` provides a hint to Redis about the number of keys to
            return per batch.

        ``_type`` filters the returned values by a particular Redis type.
            Stock Redis instances allow for the following types:
            HASH, LIST, SET, STREAM, STRING, ZSET
            Additionally, Redis modules can expose other types as well.

        For more information see https://redis.io/commands/scan
           MATCH   COUNTr   SCANr  )r2   ru  rv  rM   r   r3   r4   s          r5   scanzScanCommands.scan  sm    0 %+8MM8U+,MM8U+,MM7E*+#t##F>V>v>>r7   c              +   t   K   d}|dk7  r+ | j                   d||||d|\  }}|E d{    |dk7  r*yy7 wa*  
        Make an iterator using the SCAN command so that the client doesn't
        need to remember the cursor position.

        ``match`` allows for filtering the keys by pattern

        ``count`` provides a hint to Redis about the number of keys to
            return per batch.

        ``_type`` filters the returned values by a particular Redis type.
            Stock Redis instances allow for the following types:
            HASH, LIST, SET, STREAM, STRING, ZSET
            Additionally, Redis modules can expose other types as well.
        0r   )ru  rv  rM   r   Nr   r{  )r2   rv  rM   r   r3   ru  datas          r5   	scan_iterzScanCommands.scan_iter  sU     * k$499 U%uHNLFD OO	 k s   '86	88r   c                     ||g}||j                  d|g       ||j                  d|g        | j                  dg| S )a<  
        Incrementally return lists of elements in a set. Also return a cursor
        indicating the scan position.

        ``match`` allows for filtering the keys by pattern

        ``count`` allows for hint the minimum number of returns

        For more information see https://redis.io/commands/sscan
        rx  ry  SSCANr  r2   r   ru  rv  rM   r4   s         r5   sscanzScanCommands.sscan  S    " %)&>MM8U+,MM8U+,#t##G5f55r7   c              #   p   K   d}|dk7  r)| j                  ||||      \  }}|E d{    |dk7  r(yy7 wa   
        Make an iterator using the SSCAN command so that the client doesn't
        need to remember the cursor position.

        ``match`` allows for filtering the keys by pattern

        ``count`` allows for hint the minimum number of returns
        r~  r   ru  rv  rM   Nr  r2   r   rv  rM   ru  r  s         r5   
sscan_iterzScanCommands.sscan_iter  sA      k::d6e:TLFDOO ks   %64	66c                     ||g}||j                  d|g       ||j                  d|g        | j                  dg| S )a<  
        Incrementally return key/value slices in a hash. Also return a cursor
        indicating the scan position.

        ``match`` allows for filtering the keys by pattern

        ``count`` allows for hint the minimum number of returns

        For more information see https://redis.io/commands/hscan
        rx  ry  HSCANr  r  s         r5   hscanzScanCommands.hscan  r  r7   c              #      K   d}|dk7  r7| j                  ||||      \  }}|j                         E d{    |dk7  r6yy7 wa   
        Make an iterator using the HSCAN command so that the client doesn't
        need to remember the cursor position.

        ``match`` allows for filtering the keys by pattern

        ``count`` allows for hint the minimum number of returns
        r~  r   r  Nr  r  r  s         r5   
hscan_iterzScanCommands.hscan_iter2  sI      k::d6e:TLFDzz|## k#s   3AA	A Ascore_cast_funcc                     ||g}||j                  d|g       ||j                  d|g       d|i} | j                  dg|i |S )a  
        Incrementally return lists of elements in a sorted set. Also return a
        cursor indicating the scan position.

        ``match`` allows for filtering the keys by pattern

        ``count`` allows for hint the minimum number of returns

        ``score_cast_func`` a callable used to cast the score return value

        For more information see https://redis.io/commands/zscan
        rx  ry  r  ZSCANr  )r2   r   ru  rv  rM   r  r4   r7  s           r5   zscanzScanCommands.zscanE  sb    ( MM8U+,MM8U+,$o6#t##G@f@@@r7   c              #   r   K   d}|dk7  r*| j                  |||||      \  }}|E d{    |dk7  r)yy7 waL  
        Make an iterator using the ZSCAN command so that the client doesn't
        need to remember the cursor position.

        ``match`` allows for filtering the keys by pattern

        ``count`` allows for hint the minimum number of returns

        ``score_cast_func`` a callable used to cast the score return value
        r~  r   )ru  rv  rM   r  Nr  )r2   r   rv  rM   r  ru  r  s          r5   
zscan_iterzScanCommands.zscan_itera  sQ     " k:: / & LFD OO k s   &75	77)r   NNNr  )r   NNr  )r   r   r   r   rA   r   r#   r   r   r{  r
   r  r"   r  r  r  r  r  r  r   r  r  r   r7   r5   rt  rt    s    '+"&"&?? Xt^$? S$Y	?
 S$Y? 
?F (,"&"&	Xt^$ S$Y S$Y	 
> '+"&66 6 Xt^$	6
 S$Y6 
66 (,"&	 Xt^$ S$Y	
 
, '+"&66 6 Xt^$	6
 S$Y6 
66 (,"&	$$ Xt^$$ S$Y	$
 
$, '+"&16AA A Xt^$	A
 S$YA tX~.A 
A> (,"&16 Xt^$ S$Y	
 tX~. 
r7   rt  c                       e Zd Z	 	 	 ddeedf   deedf   deedf   defdZ	 	 dde	deedf   deedf   defdZ
	 	 ddedeedf   deedf   defd	Zddefde	deedf   deedf   d
eeef   def
dZy)AsyncScanCommandsNrv  rM   r   r.   c                   K   d}|dk7  r5 | j                   d||||d| d{   \  }}|D ]  }| 	 |dk7  r4yy7 wr}  r  )r2   rv  rM   r   r3   ru  r  ds           r5   r  zAsyncScanCommands.scan_iter  sg     * k!* "U%u"HN" LFD  	 ks   "AA AAr   c                   K   d}|dk7  r3| j                  ||||       d{   \  }}|D ]  }| 	 |dk7  r2yy7 wr  r  )r2   r   rv  rM   ru  r  r  s          r5   r  zAsyncScanCommands.sscan_iter  s]      k!%V5 ", " LFD  	 ks    A >A A c                   K   d}|dk7  rA| j                  ||||       d{   \  }}|j                         D ]  }| 	 |dk7  r@yy7 )wr  r  )r2   r   rv  rM   ru  r  its          r5   r  zAsyncScanCommands.hscan_iter  sc      k!%V5 ", " LFD jjl 	 ks    AA&A
Ar  c                   K   d}|dk7  r4| j                  |||||       d{   \  }}|D ]  }| 	 |dk7  r3yy7 wr  r  )r2   r   rv  rM   r  ru  r  r  s           r5   r  zAsyncScanCommands.zscan_iter  sc     " k!% / ", " LFD   ks   !A?AAr  r  )r   r   r   r   r#   rA   r   r   r  r"   r  r  r  r  r   r  r   r7   r5   r  r  ~  s9    (,"&"&	Xt^$ S$Y S$Y	 
@ (,"&	 Xt^$ S$Y	
 
2 (,"&	 Xt^$ S$Y	
 
2 (,"&16 Xt^$ S$Y	
 tX~. 
r7   r  c                      e Zd ZdZdededeee   ef   fdZ	dedeee   ef   fdZ
dededeee   ef   fd	Zd
edededeee   ef   fdZdededeee   ef   fdZ	 d"dedee   dedeee   ef   fdZd
edededeee   ef   fdZdededeeeed   ed   f      eed   ed   f   f   fdZdedeee   ef   fdZdedededeeeeed   ed   f         eeed   ed   f      f   fdZdedededeee   ef   fdZd#dedee   deeedf   fdZ	 d#dedee   deeedf   fdZdededeee   ef   fdZdededeee   ef   fd Zd
edededeee   ef   fd!Zy)$SetCommandsz\
    Redis commands for Set data type.
    see: https://redis.io/topics/data-types#sets
    r   r9  r.   c                 *     | j                   d|g| S )zs
        Add ``value(s)`` to set ``name``

        For more information see https://redis.io/commands/sadd
        SADDr0   r<  s      r5   saddzSetCommands.sadd       $t##FD:6::r7   c                 &    | j                  d|      S )z
        Return the number of elements in set ``name``

        For more information see https://redis.io/commands/scard
        SCARDr0   r   s     r5   scardzSetCommands.scard       ##GT22r7   r`   r:   c                 @    t        ||      } | j                  dg| S )z
        Return the difference of sets specified by ``keys``

        For more information see https://redis.io/commands/sdiff
        SDIFFr)   r1   r2   r`   r:   s      r5   sdiffzSetCommands.sdiff  s(     D$'#t##G3d33r7   r  c                 B    t        ||      } | j                  d|g| S )z
        Store the difference of sets specified by ``keys`` into a new
        set named ``dest``.  Returns the number of keys in the new set.

        For more information see https://redis.io/commands/sdiffstore
        
SDIFFSTOREr  r2   r  r`   r:   s       r5   
sdiffstorezSetCommands.sdiffstore  s*     D$'#t##L$>>>r7   c                 @    t        ||      } | j                  dg| S )z
        Return the intersection of sets specified by ``keys``

        For more information see https://redis.io/commands/sinter
        SINTERr  r  s      r5   sinterzSetCommands.sinter  (     D$'#t##H4t44r7   r   r  limitc                 :    |g|d|} | j                   dg| S )a  
        Return the cardinality of the intersect of multiple sets specified by ``keys`.

        When LIMIT provided (defaults to 0 and means unlimited), if the intersection
        cardinality reaches limit partway through the computation, the algorithm will
        exit and yield limit as the cardinality

        For more information see https://redis.io/commands/sintercard
        LIMIT
SINTERCARDr0   r2   r  r`   r  r:   s        r5   
sintercardzSetCommands.sintercard  3     /$///#t##L8488r7   c                 B    t        ||      } | j                  d|g| S )z
        Store the intersection of sets specified by ``keys`` into a new
        set named ``dest``.  Returns the number of keys in the new set.

        For more information see https://redis.io/commands/sinterstore
        SINTERSTOREr  r  s       r5   sinterstorezSetCommands.sinterstore)  *     D$'#t##M4?$??r7   r   r(   c                 (    | j                  d||      S )a  
        Return whether ``value`` is a member of set ``name``:
        - 1 if the value is a member of the set.
        - 0 if the value is not a member of the set or if key does not exist.

        For more information see https://redis.io/commands/sismember
        	SISMEMBERr0   r\  s      r5   	sismemberzSetCommands.sismember5  s     ##Ku==r7   c                 &    | j                  d|      S )z}
        Return all members of the set ``name``

        For more information see https://redis.io/commands/smembers
        SMEMBERSr0   r   s     r5   smemberszSetCommands.smembersA  s     ##J55r7   c                 B    t        ||      } | j                  d|g| S )aX  
        Return whether each value in ``values`` is a member of the set ``name``
        as a list of ``int`` in the order of ``values``:
        - 1 if the value is a member of the set.
        - 0 if the value is not a member of the set or if key does not exist.

        For more information see https://redis.io/commands/smismember
        
SMISMEMBERr  )r2   r   r9  r:   s       r5   
smismemberzSetCommands.smismemberI  s*     FD)#t##L$>>>r7   rp  r  c                 *    | j                  d|||      S )z
        Move ``value`` from set ``src`` to set ``dst`` atomically

        For more information see https://redis.io/commands/smove
        SMOVEr0   )r2   rp  r  r   s       r5   smovezSetCommands.smoveZ  s     ##GS#u==r7   NrM   c                 D    |duxr |gxs g } | j                   d|g| S )z
        Remove and return a random member of set ``name``

        For more information see https://redis.io/commands/spop
        NSPOPr0   )r2   r   rM   r:   s       r5   spopzSetCommands.spopb  s4     T!.w4"#t##FD8488r7   numberc                 D    |duxr |gxs g } | j                   d|g| S )a?  
        If ``number`` is None, returns a random member of set ``name``.

        If ``number`` is supplied, returns a list of ``number`` random
        members of set ``name``. Note this is only available when running
        Redis 2.6+.

        For more information see https://redis.io/commands/srandmember
        NSRANDMEMBERr0   )r2   r   r  r:   s       r5   srandmemberzSetCommands.srandmemberk  s4     d"06B#t##M4?$??r7   c                 *     | j                   d|g| S )zv
        Remove ``values`` from set ``name``

        For more information see https://redis.io/commands/srem
        SREMr0   r<  s      r5   sremzSetCommands.sremz  r  r7   c                 @    t        ||      } | j                  dg| S )z
        Return the union of sets specified by ``keys``

        For more information see https://redis.io/commands/sunion
        SUNIONr  r  s      r5   sunionzSetCommands.sunion  r  r7   c                 B    t        ||      } | j                  d|g| S )z
        Store the union of sets specified by ``keys`` into a new
        set named ``dest``.  Returns the number of keys in the new set.

        For more information see https://redis.io/commands/sunionstore
        SUNIONSTOREr  r  s       r5   sunionstorezSetCommands.sunionstore  r  r7   rr  r~   )r   r   r   r   r   r   r   r   rA   r  r  r   r   r  r  r  r  r  r   r  r   r  r  r   r  r   r  r  r  r  r  r   r7   r5   r  r    s6   
; ;v ;%	#8K2L ;3# 3%	#(;"< 34$ 4t 4iot6K0L 4
?
?#
?,0
?	y~s"	#
?54 5 5y7L1M 5 ;<99"&s)9479	y~s"	#9
@
@#
@,0
@	y~s"	#
@
>
> #
>	ywqz71:567wqz7ST:?U9VV	W
>6S 6U9S>3+>%? 6??!%?.2?	$uWQZ3456U71:wqz)*+	-
?"> >3 >s >uYt_d=R7S >9 9Xc] 9eCtO>T 9 26@@!)#@	sD$	@; ;v ;%	#8K2L ;54 5 5y7L1M 5
@
@#
@,0
@	y~s"	#
@r7   r  c                      e Zd ZdZdedededefdZ	 	 	 	 	 	 d5dede	e
ef   d	ed
eedf   dededeedf   deedf   defdZ	 	 	 d6dedededededeedf   dedefdZ	 	 	 	 	 d7dededededeee   ee   f   deedf   deedf   deedf   dededefdZdededefdZ	 	 	 d8deded	ededee   defdZdedededefd Zdededefd!Zdedededefd"Z	 d9deded	edee   def
d#Zdededefd$Zdedefd%Zd:ded&edefd'Zdedefd(Zdededefd)Z 	 	 d;deded*ed+ededeedf   deedf   defd,Z!	 	 	 d<ded*ed+edeedf   def
d-Z"	 	 d;d.e	eef   deedf   d/eedf   defd0Z#	 	 	 d=de$de$d.e	eef   deedf   d/eedf   d1edefd2Z%	 	 	 d>ded+ed*edeedf   def
d3Z&	 	 	 	 d?ded
eedf   dedeedf   deedf   defd4Z'y)@StreamCommandsz]
    Redis commands for Stream data type.
    see: https://redis.io/topics/streams-intro
    r   	groupnameidsr.   c                 ,     | j                   d||g| S )a  
        Acknowledges the successful processing of one or more messages.
        name: name of the stream.
        groupname: name of the consumer group.
        *ids: message ids to acknowledge.

        For more information see https://redis.io/commands/xack
        XACKr0   )r2   r   r  r  s       r5   xackzStreamCommands.xack  s      $t##FD)BcBBr7   Nfieldsidr\  approximate
nomkstreamminidr  c	                    g }	||t        d      |^t        |t              r|dk  rt        d      |	j                  d       |r|	j                  d       |	j                  t	        |             |5|	j                  d       |r|	j                  d       |	j                  |       ||	j                  d|g       |r|	j                  d       |	j                  |       t        |t              rt        |      dk(  rt        d	      |j                         D ]  }
|	j                  |
         | j                  d
|g|	 S )a  
        Add to a stream.
        name: name of the stream
        fields: dict of field/value pairs to insert into the stream
        id: Location to insert this record. By default it is appended.
        maxlen: truncate old stream members beyond this size.
        Can't be specified with minid.
        approximate: actual stream length may be slightly more than maxlen
        nomkstream: When set to true, do not make a stream
        minid: the minimum id in the stream to query.
        Can't be specified with maxlen.
        limit: specifies the maximum number of entries to retrieve

        For more information see https://redis.io/commands/xadd
        z8Only one of ```maxlen``` or ```minid``` may be specifiedr   z(XADD maxlen must be non-negative integer   MAXLENrl      MINIDri  s
   NOMKSTREAMz$XADD fields must be a non-empty dictXADD)
r   rP   rA   rQ   r   r   dictr   r  r1   )r2   r   r  r  r\  r  r  r  r  r4   r  s              r5   xaddzStreamCommands.xadd  s(   4 $&%"3VWWfc*fqj JKKMM)$d#MM#f+&MM(#d#MM% MM8U+,MM-(b&$'3v;!+;BCCLLN 	 DMM$	 #t##FD:6::r7   consumernamemin_idle_timestart_idrM   justidc                 <   	 t        |      dk  rt        d      	 i }|||||g}		 t        |      dk  rt        d      |	j                  d|g       |r|	j	                  d       d|d<    | j
                  dg|	i |S # t        $ r Y ow xY w# t        $ r Y Hw xY w)	a  
        Transfers ownership of pending stream entries that match the specified
        criteria. Conceptually, equivalent to calling XPENDING and then XCLAIM,
        but provides a more straightforward way to deal with message delivery
        failures via SCAN-like semantics.
        name: name of the stream.
        groupname: name of the consumer group.
        consumername: name of a consumer that claims the message.
        min_idle_time: filter messages that were idle less than this amount of
        milliseconds.
        start_id: filter messages with equal or greater ID.
        count: optional integer, upper limit of the number of entries that the
        command attempts to claim. Set to 100 by default.
        justid: optional boolean, false by default. Return just an array of IDs
        of messages successfully claimed, without returning the actual message

        For more information see https://redis.io/commands/xautoclaim
        r   z6XAUTOCLAIM min_idle_time must be a nonnegative integer%XPENDING count must be a integer >= 0ry     JUSTIDTparse_justid
XAUTOCLAIM)rA   r   r  r   rQ   r1   )
r2   r   r  r  r  r  rM   r  r3   r4   s
             r5   
xautoclaimzStreamCommands.xautoclaim  s    8	=!A%L  & 	<I	5zA~ GHHMM8U+, MM)$%)F>"#t##LD6DVDD!  		  		s"   B  ,B  	BB	BBmessage_idsidler  
retrycountrj   c                 "   t        |t              r|dk  rt        d      t        |t        t        f      r|st        d      i }|||t        |      g}|j                  t        |             |7t        |t              st        d      |j                  dt        |      f       |7t        |t              st        d      |j                  dt        |      f       |7t        |t              st        d      |j                  d	t        |      f       |	r,t        |	t              st        d
      |j                  d       |
r1t        |
t              st        d      |j                  d       d|d<    | j                  dg|i |S )a  
        Changes the ownership of a pending message.

        name: name of the stream.

        groupname: name of the consumer group.

        consumername: name of a consumer that claims the message.

        min_idle_time: filter messages that were idle less than this amount of
        milliseconds

        message_ids: non-empty list or tuple of message IDs to claim

        idle: optional. Set the idle time (last time it was delivered) of the
        message in ms

        time: optional integer. This is the same as idle but instead of a
        relative amount of milliseconds, it sets the idle time to a specific
        Unix time (in milliseconds).

        retrycount: optional integer. set the retry counter to the specified
        value. This counter is incremented every time a message is delivered
        again.

        force: optional boolean, false by default. Creates the pending message
        entry in the PEL even if certain specified IDs are not already in the
        PEL assigned to a different client.

        justid: optional boolean, false by default. Return just an array of IDs
        of messages successfully claimed, without returning the actual message

        For more information see https://redis.io/commands/xclaim
        r   z3XCLAIM min_idle_time must be a non negative integerzLXCLAIM message_ids must be a non empty list or tuple of message IDs to claimzXCLAIM idle must be an integers   IDLEzXCLAIM time must be an integers   TIMEz$XCLAIM retrycount must be an integers
   RETRYCOUNTzXCLAIM force must be a booleans   FORCEzXCLAIM justid must be a booleanr  Tr  XCLAIM)
rP   rA   r   r   tupler   r   r   rQ   r1   )r2   r   r  r  r  r  r  r  r   rj   r  r3   r4   s                r5   xclaimzStreamCommands.xclaim  ss   ^ --1BQRR+e}5[0 
 $()\3}CU#Vd;'(dC( @AAMM7CI./dC( @AAMM7CI./!j#. FGGMM=#j/:;eT* @AAMM(#fd+ ABBMM)$%)F>"#t##H@v@@@r7   c                 *     | j                   d|g| S )z
        Deletes one or more messages from a stream.
        name: name of the stream.
        *ids: message ids to delete.

        For more information see https://redis.io/commands/xdel
        XDELr0   )r2   r   r  s      r5   xdelzStreamCommands.xdelg  s     $t##FD7377r7   mkstreamentries_readc                 |    d|||g}|r|j                  d       ||j                  d|g        | j                  | S )a/  
        Create a new consumer group associated with a stream.
        name: name of the stream.
        groupname: name of the consumer group.
        id: ID of the last item in the stream to consider already delivered.

        For more information see https://redis.io/commands/xgroup-create
        zXGROUP CREATEs   MKSTREAMENTRIESREADr  )r2   r   r  r  r  r	  r4   s          r5   xgroup_createzStreamCommands.xgroup_createq  sK      %4T9b#IMM+&#MM=,78#t##V,,r7   c                 *    | j                  d|||      S )ax  
        Remove a specific consumer from a consumer group.
        Returns the number of pending messages that the consumer had before it
        was deleted.
        name: name of the stream.
        groupname: name of the consumer group.
        consumername: name of consumer to delete

        For more information see https://redis.io/commands/xgroup-delconsumer
        zXGROUP DELCONSUMERr0   r2   r   r  r  s       r5   xgroup_delconsumerz!StreamCommands.xgroup_delconsumer  s     ##$8$	<XXr7   c                 (    | j                  d||      S )z
        Destroy a consumer group.
        name: name of the stream.
        groupname: name of the consumer group.

        For more information see https://redis.io/commands/xgroup-destroy
        zXGROUP DESTROYr0   r2   r   r  s      r5   xgroup_destroyzStreamCommands.xgroup_destroy  s     ##$4dIFFr7   c                 *    | j                  d|||      S )a  
        Consumers in a consumer group are auto-created every time a new
        consumer name is mentioned by some command.
        They can be explicitly created by using this command.
        name: name of the stream.
        groupname: name of the consumer group.
        consumername: name of consumer to create.

        See: https://redis.io/commands/xgroup-createconsumer
        zXGROUP CREATECONSUMERr0   r  s       r5   xgroup_createconsumerz$StreamCommands.xgroup_createconsumer  s      ###T9l
 	
r7   c                 \    |||g}||j                  d|g        | j                  dg| S )a4  
        Set the consumer group last delivered ID to something else.
        name: name of the stream.
        groupname: name of the consumer group.
        id: ID of the last item in the stream to consider already delivered.

        For more information see https://redis.io/commands/xgroup-setid
        r  zXGROUP SETIDr  )r2   r   r  r  r	  r4   s         r5   xgroup_setidzStreamCommands.xgroup_setid  s?     	2&#MM=,78#t##N<V<<r7   c                 (    | j                  d||      S )z
        Returns general information about the consumers in the group.
        name: name of the stream.
        groupname: name of the consumer group.

        For more information see https://redis.io/commands/xinfo-consumers
        zXINFO CONSUMERSr0   r  s      r5   xinfo_consumerszStreamCommands.xinfo_consumers  s     ##$5tYGGr7   c                 &    | j                  d|      S )z
        Returns general information about the consumer groups of the stream.
        name: name of the stream.

        For more information see https://redis.io/commands/xinfo-groups
        zXINFO GROUPSr0   r   s     r5   xinfo_groupszStreamCommands.xinfo_groups  s     ##ND99r7   fullc                 f    |g}i }|r|j                  d       d|i} | j                  dg|i |S )z
        Returns general information about the stream.
        name: name of the stream.
        full: optional boolean, false by default. Return full summary

        For more information see https://redis.io/commands/xinfo-stream
        s   FULLr  zXINFO STREAMr   )r2   r   r  r4   r7  s        r5   xinfo_streamzStreamCommands.xinfo_stream  sE     MM'"tnG#t##NGVGwGGr7   c                 &    | j                  d|      S )z
        Returns the number of elements in a given stream.

        For more information see https://redis.io/commands/xlen
        XLENr0   r   s     r5   xlenzStreamCommands.xlen  r  r7   c                 (    | j                  d||      S )z
        Returns information about pending messages of a group.
        name: name of the stream.
        groupname: name of the consumer group.

        For more information see https://redis.io/commands/xpending
        XPENDINGr0   r  s      r5   xpendingzStreamCommands.xpending  s     ##Ji@@r7   minmaxc                    |||hdhk(  r!||t        d      | j                  ||      S ||g}|||t        d      	 t        |      dk  rt        d      |j                  d|g       	 t        |      dk  rt        d      |j                  |||g       |r|j                  |        | j                  dg|d	d
iS # t        $ r Y bw xY w# t        $ r Y Cw xY w)a  
        Returns information about pending messages, in a range.

        name: name of the stream.
        groupname: name of the consumer group.
        idle: available from  version 6.2. filter entries by their
        idle-time, given in milliseconds (optional).
        min: minimum stream ID.
        max: maximum stream ID.
        count: number of messages to return
        consumername: name of a consumer to filter by (optional).
        Nznif XPENDING is provided with idle time or consumername, it must be provided with min, max and count parameterszNXPENDING must be provided with min, max and count parameters, or none of them.r   z$XPENDING idle must be a integer >= 0IDLEr  r"  parse_detailT)r   r#  rA   r   r  rQ   r1   )	r2   r   r  r$  r%  rM   r  r  r4   s	            r5   xpending_rangezStreamCommands.xpending_range  s   , e&<#;: 
 ==y11	";#+9 
	4y1} FGGMM64.)	5zA~ GHHMM3U+, MM,'#t##JKKdKK  		  		s$   ,C .-C 	CC	CCc                     ||g}|Kt        |t              r|dk  rt        d      |j                  d       |j                  t	        |              | j
                  d|g| S )a  
        Read stream values within an interval.

        name: name of the stream.

        start: first stream ID. defaults to '-',
               meaning the earliest available.

        finish: last stream ID. defaults to '+',
                meaning the latest available.

        count: if set, only return this many items, beginning with the
               earliest available.

        For more information see https://redis.io/commands/xrange
        r(   z'XRANGE count must be a positive integerry  XRANGErP   rA   r   rQ   r   r1   )r2   r   r$  r%  rM   r4   s         r5   xrangezStreamCommands.xrange4  se    . seS)UQY IJJMM(#MM#e*%#t##Hd<V<<r7   streamsblockc                 J   g }|Kt        |t              r|dk  rt        d      |j                  d       |j                  t	        |             |Kt        |t              r|dk  rt        d      |j                  d       |j                  t	        |             t        |t
              rt        |      dk(  rt        d      |j                  d       t        |j                          \  }}|j                  |       |j                  |        | j                  d	g| S )
a  
        Block and monitor multiple streams for new data.

        streams: a dict of stream names to stream IDs, where
                   IDs indicate the last ID already seen.

        count: if set, only return this many items, beginning with the
               earliest available.

        block: number of milliseconds to wait, if nothing already present.

        For more information see https://redis.io/commands/xread
        r   z*XREAD block must be a non-negative integer   BLOCKr(   z&XREAD count must be a positive integerry  z&XREAD streams must be a non empty dict   STREAMSXREAD)rP   rA   r   rQ   r   r  r   zipr  r   r1   )r2   r.  rM   r/  r4   r`   r9  s          r5   xreadzStreamCommands.xreadT  s    & eS)UQY LMMMM(#MM#e*%eS)UQY HIIMM(#MM#e*%'4(CLA,=DEEj!GMMO,fdf#t##G5f55r7   noackc                 |   d||g}|Kt        |t              r|dk  rt        d      |j                  d       |j                  t	        |             |Kt        |t              r|dk  rt        d      |j                  d       |j                  t	        |             |r|j                  d       t        |t
              rt        |      dk(  rt        d	      |j                  d
       |j                  |j                                |j                  |j                                 | j                  dg| S )aB  
        Read from a stream via a consumer group.

        groupname: name of the consumer group.

        consumername: name of the requesting consumer.

        streams: a dict of stream names to stream IDs, where
               IDs indicate the last ID already seen.

        count: if set, only return this many items, beginning with the
               earliest available.

        block: number of milliseconds to wait, if nothing already present.
        noack: do not add messages to the PEL

        For more information see https://redis.io/commands/xreadgroup
        s   GROUPr(   z+XREADGROUP count must be a positive integerry  r   z/XREADGROUP block must be a non-negative integerr1  s   NOACKz+XREADGROUP streams must be a non empty dictr2  
XREADGROUP)rP   rA   r   rQ   r   r  r   r   r`   r9  r1   )r2   r  r  r.  rM   r/  r6  r4   s           r5   
xreadgroupzStreamCommands.xreadgroupz  s   6 %-i#FeS)UQY MNNMM(#MM#e*%eS)UQY QRRMM(#MM#e*%MM(#'4(CLA,=IJJj!glln%gnn&'#t##L:6::r7   c                     ||g}|Kt        |t              r|dk  rt        d      |j                  d       |j                  t	        |              | j
                  d|g| S )a  
        Read stream values within an interval, in reverse order.

        name: name of the stream

        start: first stream ID. defaults to '+',
               meaning the latest available.

        finish: last stream ID. defaults to '-',
                meaning the earliest available.

        count: if set, only return this many items, beginning with the
               latest available.

        For more information see https://redis.io/commands/xrevrange
        r(   z*XREVRANGE count must be a positive integerry  	XREVRANGEr,  )r2   r   r%  r$  rM   r4   s         r5   	xrevrangezStreamCommands.xrevrange  se    . %(:eS)UQY LMMMM(#MM#e*%#t##K???r7   c                 p   g }||t        d      ||t        d      ||j                  d       ||j                  d       |r|j                  d       ||j                  |       ||j                  |       |"|j                  d       |j                  |        | j                  d|g| S )a  
        Trims old messages from a stream.
        name: name of the stream.
        maxlen: truncate old stream messages beyond this size
        Can't be specified with minid.
        approximate: actual stream length may be slightly more than maxlen
        minid: the minimum id in the stream to query
        Can't be specified with maxlen.
        limit: specifies the maximum number of entries to retrieve

        For more information see https://redis.io/commands/xtrim
        z4Only one of ``maxlen`` or ``minid`` may be specifiedz0One of ``maxlen`` or ``minid`` must be specifiedr  r  rl   ri  XTRIMr  )r2   r   r\  r  r  r  r4   s          r5   xtrimzStreamCommands.xtrim  s    ( $&%"3RSS>emNOOMM)$MM(#MM$MM&!MM% MM(#MM% #t##GT;F;;r7   )r  NTFNN)z0-0NF)NNNFF)$FNr~   r  r  )-+N)NNF)rB  rA  N)NTNN)(r   r   r   r   r"   r    r%   r   r  r   r   r   r   rA   r   r  r   r  r   r   r  r  r   r  r  r  r  r  r  r  r  r   r#  r)  r-  r5  r   r9  r<  r?  r   r7   r5   r  r    s   
	C 	C& 	C	 	Ci 	C #'  (,"&3;3; VZ'(3; 	3;
 c4i 3; 3; 3; Y_%3; S$Y3; 
3;v $"&1E1E 1E  	1E
 1E 1E S$Y1E 1E 
1Et "&!%'+QAQA QA  	QA
 QA 4	?E),<<=QA CIQA CIQA #t)$QA QA QA 
QAf8 8Y 89 8 &*-- - 	-
 - sm- 
-0YY%+Y;DY	YG4 GF Gy G

%+
;D
	
, '+== = 	=
 sm= 
=(HD HV H	 H: :) :H HT Hi H2 2) 2AT Af A A" 04!%7L7L 7L 	7L
 7L 7L ItO,7L CI7L 
7Lx "&== = 	=
 S$Y= 
=F #'"&	$6dIo&$6 S$Y$6 S$Y	$6
 
$6V #'"&-;-; -; dIo&	-;
 S$Y-; S$Y-; -; 
-;d "&@@ @ 	@
 S$Y@ 
@F $( (,"&)<)< c4i )< 	)<
 Y_%)< S$Y)< 
)<r7   r  c                   `   e Zd ZdZ	 	 	 	 	 	 dKdedeeef   dedededed	ed
ede	fdZ
dede	fdZdededede	fdZdLdedede	fdZdedede	fdZdededede	fdZ	 dMdedeedf   dede	fdZ	 dNdedeee   eeef   f   deedf   de	fdZ	 dOdedee   dedeee   ef   fdZd  ZdNded!eedf   de	fd"ZdNded!eedf   de	fd#Z	 dMd$ed!edede	fd%ZdOded&e de	fd'Z!dOded&e de	fd(Z"	 	 	 dPd)edee   de#e   de#e   d!e#e   deee$   e$f   fd*Z%	 	 	 dPd&ededee   de#e   de#e   d!e#e   de#e$   fd+Z&ddddeddfdeedf   ded,ed-ed.ed/ed0eded1ee'e(df   d2eedf   d3eedf   de	fd4Z)ddeddddfded,ed-ed.eded1ee'e(f   d/ed0ed2ed3ede	fd5Z*defded,ed-eded1ee'e(f   de	fd6Z+	 	 	 	 	 dQdeded,ed-ed/ed0ed.ed2eedf   d3eedf   de	fd7Z,	 	 dRdededed,eedf   d3eedf   de	fd8Z-	 	 dRdededed,eedf   d3eedf   de	fd9Z.dddefdededed,eedf   d3eedf   ded1ee'e(f   de	fd:Z/dddefdededed,eedf   d3eedf   ded1ee'e(f   fd;Z0	 dLdeded<ede	fd=Z1ded>e2de	fd?Z3dededede	fd@Z4dededede	fdAZ5dededede	fdBZ6	 dLdeded<ede	fdCZ7dedede	fdDZ8	 	 dMdeee   eeef   f   deedf   dede	fdEZ9	 dNdedeee   eeef   f   deedf   de	fdFZ:d$edGee   de	fdHZ;	 dNdIedeedf   deee   eeef   f   deedf   de	f
dJZ<y)SSortedSetCommandszw
    Redis commands for Sorted Sets data type.
    see: https://redis.io/topics/data-types-intro#redis-sorted-sets
    Fr   r{  r)  r*  chr  r+  r,  r.   c	                 N   |st        d      |r|rt        d      |r|rt        d      |rt        |      dk7  rt        d      |r|s|rt        d      g }	i }
|r|	j                  d       |r|	j                  d       |r|	j                  d	       |r|	j                  d
       d|
d<   |r|	j                  d       |r|	j                  d       |j                         D ]*  }|	j                  |d          |	j                  |d          ,  | j                  d|g|	i |
S )a  
        Set any number of element-name, score pairs to the key ``name``. Pairs
        are specified as a dict of element-names keys to score values.

        ``nx`` forces ZADD to only create new elements and not to update
        scores for elements that already exist.

        ``xx`` forces ZADD to only update scores of elements that already
        exist. New elements will not be added.

        ``ch`` modifies the return value to be the numbers of elements changed.
        Changed elements include new elements that were added and elements
        whose scores changed.

        ``incr`` modifies ZADD to behave like ZINCRBY. In this mode only a
        single element/score pair can be specified and the score is the amount
        the existing score will be incremented by. When using this mode the
        return value of ZADD will be the new score of the element.

        ``LT`` Only update existing elements if the new score is less than
        the current score. This flag doesn't prevent adding new elements.

        ``GT`` Only update existing elements if the new score is greater than
        the current score. This flag doesn't prevent adding new elements.

        The return value of ZADD varies based on the mode specified. With no
        options, ZADD returns the number of new elements added to the sorted
        set.

        ``NX``, ``LT``, and ``GT`` are mutually exclusive options.

        See: https://redis.io/commands/ZADD
        z-ZADD requires at least one element/score pairz)ZADD allows either 'nx' or 'xx', not bothz)ZADD allows either 'gt' or 'lt', not bothr(   zFZADD option 'incr' only works when passing a single element/score pairz/Only one of 'nx', 'lt', or 'gr' may be defined.s   NXs   XXs   CHs   INCRTas_scores   GTs   LTr   ZADD)r   r   rQ   r  r1   )r2   r   r{  r)  r*  rE  r  r+  r,  r4   r7  r  s               r5   zaddzSortedSetCommands.zadd  s/   X KLL"GHH"GHHCLA%,  2MNN#%MM% MM% MM% MM'""&GJMM% MM% MMO 	#DMM$q'"MM$q'"	# $t##FDE6EWEEr7   c                 &    | j                  d|      S )z
        Return the number of elements in the sorted set ``name``

        For more information see https://redis.io/commands/zcard
        ZCARDr0   r   s     r5   zcardzSortedSetCommands.zcardL  r  r7   r$  r%  c                 *    | j                  d|||      S )z
        Returns the number of elements in the sorted set at key ``name`` with
        a score between ``min`` and ``max``.

        For more information see https://redis.io/commands/zcount
        ZCOUNTr0   r2   r   r$  r%  s       r5   zcountzSortedSetCommands.zcountT  s     ##HdC==r7   r`   
withscoresc                 j    t        |      g|}|r|j                  d        | j                  dg| S )z
        Returns the difference between the first and all successive input
        sorted sets provided in ``keys``.

        For more information see https://redis.io/commands/zdiff
        
WITHSCORESZDIFF)r   rQ   r1   )r2   r`   rQ  r4   s       r5   zdiffzSortedSetCommands.zdiff]  s<     d)#d#MM,'#t##G5f55r7   r  c                 F    t        |      g|} | j                  d|g| S )z
        Computes the difference between the first and all successive input
        sorted sets provided in ``keys`` and stores the result in ``dest``.

        For more information see https://redis.io/commands/zdiffstore
        
ZDIFFSTORE)r   r1   )r2   r  r`   r4   s       r5   
zdiffstorezSortedSetCommands.zdiffstorei  s/     d)#d##t##L$@@@r7   r  r   c                 *    | j                  d|||      S )z
        Increment the score of ``value`` in sorted set ``name`` by ``amount``

        For more information see https://redis.io/commands/zincrby
        ZINCRBYr0   )r2   r   r  r   s       r5   zincrbyzSortedSetCommands.zincrbys  s     ##ItVUCCr7   N	aggregatec                 .    | j                  dd|||      S )a1  
        Return the intersect of multiple sorted sets specified by ``keys``.
        With the ``aggregate`` option, it is possible to specify how the
        results of the union are aggregated. This option defaults to SUM,
        where the score of an element is summed across the inputs where it
        exists. When this option is set to either MIN or MAX, the resulting
        set will contain the minimum or maximum score of an element across
        the inputs where it exists.

        For more information see https://redis.io/commands/zinter
        ZINTERNrQ  _zaggregater2   r`   r\  rQ  s       r5   zinterzSortedSetCommands.zinter{        $iJWWr7   c                 *    | j                  d|||      S )a+  
        Intersect multiple sorted sets specified by ``keys`` into a new
        sorted set, ``dest``. Scores in the destination will be aggregated
        based on the ``aggregate``. This option defaults to SUM, where the
        score of an element is summed across the inputs where it exists.
        When this option is set to either MIN or MAX, the resulting set will
        contain the minimum or maximum score of an element across the inputs
        where it exists.

        For more information see https://redis.io/commands/zinterstore
        ZINTERSTOREr`  r2   r  r`   r\  s       r5   zinterstorezSortedSetCommands.zinterstore  s    " tT9EEr7   r  r  c                 :    |g|d|} | j                   dg| S )a  
        Return the cardinality of the intersect of multiple sorted sets
        specified by ``keys`.
        When LIMIT provided (defaults to 0 and means unlimited), if the intersection
        cardinality reaches limit partway through the computation, the algorithm will
        exit and yield limit as the cardinality

        For more information see https://redis.io/commands/zintercard
        r  
ZINTERCARDr0   r  s        r5   
zintercardzSortedSetCommands.zintercard  r  r7   c                 *    | j                  d|||      S )z
        Return the number of items in the sorted set ``name`` between the
        lexicographical range ``min`` and ``max``.

        For more information see https://redis.io/commands/zlexcount
        	ZLEXCOUNTr0   rO  s       r5   	zlexcountzSortedSetCommands.zlexcount  s     ##KsC@@r7   rM   c                 R    |duxr |gxs g }ddi} | j                   d|g|i |S )z
        Remove and return up to ``count`` members with the highest scores
        from the sorted set ``name``.

        For more information see https://redis.io/commands/zpopmax
        NrQ  TZPOPMAXr0   r2   r   rM   r:   r7  s        r5   zpopmaxzSortedSetCommands.zpopmax  C     T!.w4"&#t##ItFdFgFFr7   c                 R    |duxr |gxs g }ddi} | j                   d|g|i |S )z
        Remove and return up to ``count`` members with the lowest scores
        from the sorted set ``name``.

        For more information see https://redis.io/commands/zpopmin
        NrQ  TZPOPMINr0   rq  s        r5   zpopminzSortedSetCommands.zpopmin  rs  r7   rw   c                 z    g }||j                  |       |r|j                  d        | j                  d|g| S )a  
        Return a random element from the sorted set value stored at key.

        ``count`` if the argument is positive, return an array of distinct
        fields. If called with a negative count, the behavior changes and
        the command is allowed to return the same field multiple times.
        In this case, the number of returned fields is the absolute value
        of the specified count.

        ``withscores`` The optional WITHSCORES modifier changes the reply so it
        includes the respective scores of the randomly selected elements from
        the sorted set.

        For more information see https://redis.io/commands/zrandmember
        rS  ZRANDMEMBERr   )r2   rw   rM   rQ  r  s        r5   zrandmemberzSortedSetCommands.zrandmember  sD    $ MM% MM,'#t##M3@@@r7   r   c                 j    |d}t        |d      }|j                  |        | j                  dg| S )a  
        ZPOPMAX a value off of the first non-empty sorted set
        named in the ``keys`` list.

        If none of the sorted sets in ``keys`` has a value to ZPOPMAX,
        then block for ``timeout`` seconds, or until a member gets added
        to one of the sorted sets.

        If timeout is 0, then block indefinitely.

        For more information see https://redis.io/commands/bzpopmax
        Nr   BZPOPMAXr  r  s      r5   bzpopmaxzSortedSetCommands.bzpopmax  s>     ?GD$'G#t##J666r7   c                 j    |d}t        |d      }|j                  |        | j                  dg| S )a  
        ZPOPMIN a value off of the first non-empty sorted set
        named in the ``keys`` list.

        If none of the sorted sets in ``keys`` has a value to ZPOPMIN,
        then block for ``timeout`` seconds, or until a member gets added
        to one of the sorted sets.

        If timeout is 0, then block indefinitely.

        For more information see https://redis.io/commands/bzpopmin
        Nr   BZPOPMINr  r  s      r5   bzpopminzSortedSetCommands.bzpopmin  s>     ?G!-dD!9G#t##J666r7   r%  c                     |g|z   }|r|s|s|st         |r|j                  d       n|j                  d       |dk7  r|j                  d|g        | j                  dg| S )z
        Pop ``count`` values (default 1) off of the first non-empty sorted set
        named in the ``keys`` list.
        For more information see https://redis.io/commands/zmpop
        MINMAXr(   r"  ZMPOPr   rQ   r   r1   )r2   r%  r`   r$  r%  rM   r:   s          r5   zmpopzSortedSetCommands.zmpop  si     zD CSOKKKKA:KK%()#t##G3d33r7   c                     ||g|}|r|s|s|st        d      |r|j                  d       n|j                  d       |j                  d|g        | j                  dg| S )a  
        Pop ``count`` values (default 1) off of the first non-empty sorted set
        named in the ``keys`` list.

        If none of the sorted sets in ``keys`` has a value to pop,
        then block for ``timeout`` seconds, or until a member gets added
        to one of the sorted sets.

        If timeout is 0, then block indefinitely.

        For more information see https://redis.io/commands/bzmpop
        z+Either min or max, but not both must be setr  r  r"  BZMPOPr  )r2   r   r  r`   r$  r%  rM   r:   s           r5   bzmpopzSortedSetCommands.bzmpop%  sl    * (4(CSIJJKKKKWe$%#t##H4t44r7   r  r  rc  byscorebylexr  r:  r  c                    |r|rt        d      ||||t        d      |r|	rt        d      |g}|r|j                  |       |j                  |||g       |r|j                  d       |r|j                  d       |r|j                  d       |||j                  d||g       |	r|j                  d       |	|
d	} | j                  |i |S )
Nz8``byscore`` and ``bylex`` can not be specified together.z.``offset`` and ``num`` must both be specified.z;``withscores`` not supported in combination with ``bylex``.BYSCOREBYLEXREVr  rS  rQ  r  r  )r2   r   r  r   r  r  rc  r  r  rQ  r  r:  r  r4   r7  s                  r5   _zrangezSortedSetCommands._zrangeE  s     uVWW3;COLMMZM  MM$tUC()MM)$MM'"MM% #/MM7FC01MM,'!+P#t##V7w77r7   c                 x    |s|s|	|
|r| j                  |||||      S | j                  dd|||||||||	|
      S )a  
        Return a range of values from sorted set ``name`` between
        ``start`` and ``end`` sorted in ascending order.

        ``start`` and ``end`` can be negative, indicating the end of the range.

        ``desc`` a boolean indicating whether to sort the results in reversed
        order.

        ``withscores`` indicates to return the scores along with the values.
        The return type is a list of (value, score) pairs.

        ``score_cast_func`` a callable used to cast the score return value.

        ``byscore`` when set to True, returns the range of elements from the
        sorted set having scores equal or between ``start`` and ``end``.

        ``bylex`` when set to True, returns the range of elements from the
        sorted set between the ``start`` and ``end`` lexicographical closed
        range intervals.
        Valid ``start`` and ``end`` must start with ( or [, in order to specify
        whether the range interval is exclusive or inclusive, respectively.

        ``offset`` and ``num`` are specified, then return a slice of the range.
        Can't be provided when using ``bylex``.

        For more information see https://redis.io/commands/zrange
        NZRANGE)	zrevranger  )r2   r   r  r  rc  rQ  r  r  r  r:  r  s              r5   zrangezSortedSetCommands.zrangem  s`    V u&.S[d>>$sJPP||
 	
r7   c                 b    d|||g}|r|j                  d       ||d} | j                  |i |S )a  
        Return a range of values from sorted set ``name`` between
        ``start`` and ``end`` sorted in descending order.

        ``start`` and ``end`` can be negative, indicating the end of the range.

        ``withscores`` indicates to return the scores along with the values
        The return type is a list of (value, score) pairs

        ``score_cast_func`` a callable used to cast the score return value

        For more information see https://redis.io/commands/zrevrange
        	ZREVRANGE
   WITHSCORESr  r   )r2   r   r  r  rQ  r  r4   r7  s           r5   r  zSortedSetCommands.zrevrange  sC    * tUC0MM-(!+P#t##V7w77r7   c
                 :    | j                  d|||||||dd||	      S )a  
        Stores in ``dest`` the result of a range of values from sorted set
        ``name`` between ``start`` and ``end`` sorted in ascending order.

        ``start`` and ``end`` can be negative, indicating the end of the range.

        ``byscore`` when set to True, returns the range of elements from the
        sorted set having scores equal or between ``start`` and ``end``.

        ``bylex`` when set to True, returns the range of elements from the
        sorted set between the ``start`` and ``end`` lexicographical closed
        range intervals.
        Valid ``start`` and ``end`` must start with ( or [, in order to specify
        whether the range interval is exclusive or inclusive, respectively.

        ``desc`` a boolean indicating whether to sort the results in reversed
        order.

        ``offset`` and ``num`` are specified, then return a slice of the range.
        Can't be provided when using ``bylex``.

        For more information see https://redis.io/commands/zrangestore
        ZRANGESTOREFN)r  )
r2   r  r   r  r  r  r  rc  r:  r  s
             r5   zrangestorezSortedSetCommands.zrangestore  s:    F ||
 	
r7   c                     ||||t        d      d|||g}|||j                  d||g        | j                  | S )a  
        Return the lexicographical range of values from sorted set ``name``
        between ``min`` and ``max``.

        If ``start`` and ``num`` are specified, then return a slice of the
        range.

        For more information see https://redis.io/commands/zrangebylex
        rh  ZRANGEBYLEXri  r   r   r1   )r2   r   r$  r%  r  r  r4   s          r5   zrangebylexzSortedSetCommands.zrangebylex  s`    " #+3?u}JKKsC0MM8UC01#t##V,,r7   c                     ||||t        d      d|||g}|||j                  d||g        | j                  | S )a)  
        Return the reversed lexicographical range of values from sorted set
        ``name`` between ``max`` and ``min``.

        If ``start`` and ``num`` are specified, then return a slice of the
        range.

        For more information see https://redis.io/commands/zrevrangebylex
        rh  ZREVRANGEBYLEXr  r  )r2   r   r%  r$  r  r  r4   s          r5   zrevrangebylexz SortedSetCommands.zrevrangebylex  s`    " #+3?u}JKK"D#s3MM7E3/0#t##V,,r7   c                     ||||t        d      d|||g}|||j                  d||g       |r|j                  d       ||d}	 | j                  |i |	S )a  
        Return a range of values from the sorted set ``name`` with scores
        between ``min`` and ``max``.

        If ``start`` and ``num`` are specified, then return a slice
        of the range.

        ``withscores`` indicates to return the scores along with the values.
        The return type is a list of (value, score) pairs

        `score_cast_func`` a callable used to cast the score return value

        For more information see https://redis.io/commands/zrangebyscore
        rh  ZRANGEBYSCOREr  rS  r  r   r   rQ   r1   )
r2   r   r$  r%  r  r  rQ  r  r4   r7  s
             r5   zrangebyscorezSortedSetCommands.zrangebyscore'  s~    0 #+3?u}JKK!4c2MM7E3/0MM,'!+P#t##V7w77r7   c                     ||||t        d      d|||g}|||j                  d||g       |r|j                  d       ||d}	 | j                  |i |	S )a  
        Return a range of values from the sorted set ``name`` with scores
        between ``min`` and ``max`` in descending order.

        If ``start`` and ``num`` are specified, then return a slice
        of the range.

        ``withscores`` indicates to return the scores along with the values.
        The return type is a list of (value, score) pairs

        ``score_cast_func`` a callable used to cast the score return value

        For more information see https://redis.io/commands/zrevrangebyscore
        rh  ZREVRANGEBYSCOREr  rS  r  r  )
r2   r   r%  r$  r  r  rQ  r  r4   r7  s
             r5   zrevrangebyscorez"SortedSetCommands.zrevrangebyscoreI  s~    0 #+3?u}JKK$dC5MM7E3/0MM,'!+P#t##V7w77r7   	withscorec                 T    |r| j                  d||d      S | j                  d||      S )a$  
        Returns a 0-based value indicating the rank of ``value`` in sorted set
        ``name``.
        The optional WITHSCORE argument supplements the command's
        reply with the score of the element returned.

        For more information see https://redis.io/commands/zrank
        ZRANK	WITHSCOREr0   r2   r   r   r  s       r5   zrankzSortedSetCommands.zrankk  s3     ''ukJJ##GT599r7   r9  c                 *     | j                   d|g| S )z
        Remove member ``values`` from sorted set ``name``

        For more information see https://redis.io/commands/zrem
        ZREMr0   r<  s      r5   zremzSortedSetCommands.zrem}  r  r7   c                 *    | j                  d|||      S )a  
        Remove all elements in the sorted set ``name`` between the
        lexicographical range specified by ``min`` and ``max``.

        Returns the number of elements removed.

        For more information see https://redis.io/commands/zremrangebylex
        ZREMRANGEBYLEXr0   rO  s       r5   zremrangebylexz SortedSetCommands.zremrangebylex  s     ##$4dCEEr7   c                 *    | j                  d|||      S )ae  
        Remove all elements in the sorted set ``name`` with ranks between
        ``min`` and ``max``. Values are 0-based, ordered from smallest score
        to largest. Values can be negative indicating the highest scores.
        Returns the number of elements removed

        For more information see https://redis.io/commands/zremrangebyrank
        ZREMRANGEBYRANKr0   rO  s       r5   zremrangebyrankz!SortedSetCommands.zremrangebyrank  s     ##$5tS#FFr7   c                 *    | j                  d|||      S )z
        Remove all elements in the sorted set ``name`` with scores
        between ``min`` and ``max``. Returns the number of elements removed.

        For more information see https://redis.io/commands/zremrangebyscore
        ZREMRANGEBYSCOREr0   rO  s       r5   zremrangebyscorez"SortedSetCommands.zremrangebyscore  s     ##$6c3GGr7   c                 T    |r| j                  d||d      S | j                  d||      S )a6  
        Returns a 0-based value indicating the descending rank of
        ``value`` in sorted set ``name``.
        The optional ``withscore`` argument supplements the command's
        reply with the score of the element returned.

        For more information see https://redis.io/commands/zrevrank
        ZREVRANKr  r0   r  s       r5   zrevrankzSortedSetCommands.zrevrank  s3     ''
D%MM##Je<<r7   c                 (    | j                  d||      S )z
        Return the score of element ``value`` in sorted set ``name``

        For more information see https://redis.io/commands/zscore
        ZSCOREr0   r\  s      r5   zscorezSortedSetCommands.zscore  s     ##HdE::r7   c                 .    | j                  dd|||      S )a@  
        Return the union of multiple sorted sets specified by ``keys``.
        ``keys`` can be provided as dictionary of keys and their weights.
        Scores will be aggregated based on the ``aggregate``, or SUM if
        none is provided.

        For more information see https://redis.io/commands/zunion
        ZUNIONNr_  r`  rb  s       r5   zunionzSortedSetCommands.zunion  rd  r7   c                 *    | j                  d|||      S )a   
        Union multiple sorted sets specified by ``keys`` into
        a new sorted set, ``dest``. Scores in the destination will be
        aggregated based on the ``aggregate``, or SUM if none is provided.

        For more information see https://redis.io/commands/zunionstore
        ZUNIONSTOREr`  rg  s       r5   zunionstorezSortedSetCommands.zunionstore  s     tT9EEr7   membersc                 N    |st        d      |g|z   } | j                  dg| S )ay  
        Returns the scores associated with the specified members
        in the sorted set stored at key.
        ``members`` should be a list of the member name.
        Return type is a list of score.
        If the member does not exist, a None will be returned
        in corresponding position.

        For more information see https://redis.io/commands/zmscore
        z(ZMSCORE members must be a non-empty listZMSCOREr   )r2   rw   r  r4   s       r5   zmscorezSortedSetCommands.zmscore  s6     FGG#t##I777r7   r   c                     |g}||j                  |       |j                  t        |             t        |t              r!|j	                         |j                         }}nd }|j                  |       |r"|j                  d       |j                  |       |r@|j                         dv r#|j                  d       |j                  |       nt        d      |j                  dd      r|j                  d        | j                  |i |S )Ns   WEIGHTS)SUMr  r  s	   AGGREGATEz!aggregate can be sum, min or max.rQ  Fr  )rQ   r   rP   r  r`   r9  r   r  r   r  r1   )r2   r   r  r`   r\  r7  r4   weightss           r5   ra  zSortedSetCommands._zaggregate  s     %,9MM$c$i dD! IIK'DGdMM*%MM'" $99l+i( CDD;;|U+MM-(#t##V7w77r7   )FFFFFFr  r  r~   rr  )FFr(   )FFFNNr  )=r   r   r   r   r"   r   r   r   r   r   rI  rL  r'   rP  r!   rU  rX  r  r[  r   r   rc  r   rh  rA   r   r   rk  rn  rr  rv  ry  r&   r|  r  r   r   r  r  r  r   r  r  r  r  r  r  r  r  r  r   r  r  r  r  r  r  r  r  r  ra  r   r7   r5   rD  rD    s	    LFLF *,-LF 	LF
 LF LF LF LF LF 
LF\3$ 39 3>4 >l > >) >
6% 
6T 
6i 
6At A5 AY ADD D% D
 Dy D SXXX&+CI&6XKOX	X( '+	FF HTNGGUN$;;<F d#	F
 
F( ;<99"&s)9479	y~s"	#9A	GD 	GsDy)9 	GY 	G	GD 	GsDy)9 	GY 	G @EAA #A8<A	A47U 7[ 7 7&7U 7[ 7 7. $# 44 3i4 d^	4
 d^4 }4 
y$	%4< $# 55 5 3i	5
 d^5 d^5 }5 
$5N  7<#' $&8 D$J&8 	&8
 &8 &8 &8 &8 &8 &8 tXt34&8 c4i &8 39&8 
&8Z  16;
;
 ;
 	;

 ;
 ;
 tX~.;
 ;
 ;
 ;
 ;
 
;
D !1688 8 	8
 8 tX~.8 
8B #' $0
0
 0
 	0

 0
 0
 0
 0
 c4i 0
 390
 
0
n #' $-- - 	-
 S$Y- 39- 
-: #' $-- - 	-
 S$Y- 39- 
-: #' $ 16 8 8  8 	 8
 S$Y 8 39 8  8 tX~. 8 
 8N #' $ 16 8 8  8 	 8
 S$Y 8 39 8  8 tX~. 8L  	:: : 	:
 
:$; ; ;9 ;	F4 	Fj 	Fz 	Fi 	F	GD 	Gs 	G 	G 	G	H	H+	H2>	H		H  	== = 	=
 
=$;4 ;
 ;y ; '+ 	XHTNGGUN$;;<X d#X 	X
 
X( '+	FF HTNGGUN$;;<F d#	F
 
F84 8$s) 8	 8* '+88 D$J8 HTNGGUN$;;<	8
 d#8 
8r7   rD  c                   H    e Zd ZdZdededefdZdedefdZdededefd	Z	y
)HyperlogCommandszr
    Redis commands of HyperLogLogs data type.
    see: https://redis.io/topics/data-types-intro#hyperloglogs
    r   r9  r.   c                 *     | j                   d|g| S )z
        Adds the specified elements to the specified HyperLogLog.

        For more information see https://redis.io/commands/pfadd
        PFADDr0   r<  s      r5   pfaddzHyperlogCommands.pfadd  r>  r7   sourcesc                 (     | j                   dg| S )z
        Return the approximated cardinality of
        the set observed by the HyperLogLog at key(s).

        For more information see https://redis.io/commands/pfcount
        PFCOUNTr0   )r2   r  s     r5   pfcountzHyperlogCommands.pfcount  s     $t##I888r7   r  c                 *     | j                   d|g| S )z
        Merge N different HyperLogLogs into a single one.

        For more information see https://redis.io/commands/pfmerge
        PFMERGEr0   )r2   r  r  s      r5   pfmergezHyperlogCommands.pfmerge(  s     $t##It>g>>r7   N)
r   r   r   r   r"   r   r   r  r  r  r   r7   r5   r  r    sN    
<$ < <I <9 9 9?D ?D ?Y ?r7   r  c                   J   e Zd ZdZdededeee   ef   fdZ	dededeee
   e
f   fdZdededeeee      ee   f   fdZdedeee   ef   fd	Z	 ddeded
edeee   ef   fdZ	 ddeded
edeee   ef   fdZdedeee   ef   fdZdedeee   ef   fdZ	 	 	 	 ddedee   dee   dee   dee   deee   ef   fdZdedededeee
   e
f   fdZdededeee   ef   fdZdedededeee   ef   fdZdedeee   ef   fdZdededeee   ef   fdZy)HashCommandszk
    Redis commands for Hash data type.
    see: https://redis.io/topics/data-types-intro#redis-hashes
    r   r`   r.   c                 *     | j                   d|g| S )zu
        Delete ``keys`` from hash ``name``

        For more information see https://redis.io/commands/hdel
        HDELr0   )r2   r   r`   s      r5   hdelzHashCommands.hdel:  s     $t##FD8488r7   rw   c                 (    | j                  d||      S )z
        Returns a boolean indicating if ``key`` exists within hash ``name``

        For more information see https://redis.io/commands/hexists
        HEXISTSr0   r2   r   rw   s      r5   hexistszHashCommands.hexistsB  s     ##ItS99r7   c                 (    | j                  d||      S )z
        Return the value of ``key`` within the hash ``name``

        For more information see https://redis.io/commands/hget
        HGETr0   r  s      r5   hgetzHashCommands.hgetJ  s     ##FD#66r7   c                 &    | j                  d|      S )z
        Return a Python dict of the hash's name/value pairs

        For more information see https://redis.io/commands/hgetall
        HGETALLr0   r   s     r5   hgetallzHashCommands.hgetallT  r  r7   r  c                 *    | j                  d|||      S )z
        Increment the value of ``key`` in hash ``name`` by ``amount``

        For more information see https://redis.io/commands/hincrby
        HINCRBYr0   r2   r   rw   r  s       r5   hincrbyzHashCommands.hincrby\  s     ##ItS&AAr7   c                 *    | j                  d|||      S )z
        Increment the value of ``key`` in hash ``name`` by floating ``amount``

        For more information see https://redis.io/commands/hincrbyfloat
        HINCRBYFLOATr0   r  s       r5   hincrbyfloatzHashCommands.hincrbyfloatf  s     ##ND#vFFr7   c                 &    | j                  d|      S )z
        Return the list of keys within hash ``name``

        For more information see https://redis.io/commands/hkeys
        HKEYSr0   r   s     r5   hkeyszHashCommands.hkeysp  r  r7   c                 &    | j                  d|      S )z
        Return the number of elements in hash ``name``

        For more information see https://redis.io/commands/hlen
        HLENr0   r   s     r5   hlenzHashCommands.hlenx  r  r7   Nr   r{  r  c                     ||s|st        d      |xs g }||j                  ||f       |r&|j                         D ]  }|j                  |         | j                  d|g| S )a{  
        Set ``key`` to ``value`` within hash ``name``,
        ``mapping`` accepts a dict of key/value pairs that will be
        added to hash ``name``.
        ``items`` accepts a list of key/value pairs that will be
        added to hash ``name``.
        Returns the number of fields that were added.

        For more information see https://redis.io/commands/hset
        z'hset' with no key value pairsHSET)r   r   r  r1   )r2   r   rw   r   r{  r  r  s          r5   hsetzHashCommands.hset  sw    $ ;wu<==?LL#u& #T"# $t##FD9599r7   c                 *    | j                  d|||      S )z
        Set ``key`` to ``value`` within hash ``name`` if ``key`` does not
        exist.  Returns 1 if HSETNX created a field, otherwise 0.

        For more information see https://redis.io/commands/hsetnx
        HSETNXr0   )r2   r   rw   r   s       r5   hsetnxzHashCommands.hsetnx  s     ##HdC??r7   c                 (   t        j                  | j                  j                   d| j                  j                   dt        d       |st        d      g }|j                         D ]  }|j                  |         | j                  d|g| S )z
        Set key to value within hash ``name`` for each corresponding
        key and value from the ``mapping`` dict.

        For more information see https://redis.io/commands/hmset
        z.hmset() is deprecated. Use z.hset() instead.rP  )
stacklevelz"'hmset' with 'mapping' of length 0HMSET)	r  r  r  r   r  r   r  r   r1   )r2   r   r{  r  r  s        r5   hmsetzHashCommands.hmset  s     	~~&&' (>>**++;=		
 @AAMMO 	DLL	#t##GT:E::r7   r:   c                 B    t        ||      } | j                  d|g| S )z
        Returns a list of values ordered identically to ``keys``

        For more information see https://redis.io/commands/hmget
        HMGETr  )r2   r   r`   r:   s       r5   hmgetzHashCommands.hmget  s*     D$'#t##GT9D99r7   c                 &    | j                  d|      S )z
        Return the list of values within hash ``name``

        For more information see https://redis.io/commands/hvals
        HVALSr0   r   s     r5   hvalszHashCommands.hvals  r  r7   c                 (    | j                  d||      S )z
        Return the number of bytes stored in the value of ``key``
        within hash ``name``

        For more information see https://redis.io/commands/hstrlen
        HSTRLENr0   r  s      r5   hstrlenzHashCommands.hstrlen  s     ##ItS99r7   r  r  )NNNN)r   r   r   r   r   r   r   r   rA   r  r   r  r   r  r  r  r  r  r  r  r  r   r  r  r  r  r  r  r   r7   r5   r  r  4  s   
9 9T 9eIcNC4G.H 9:C :c :eIdOT4I.J :77!7	y#'#6	775C 5E)D/4*?$@ 5 23BB!B+.B	y~s"	#B 47GG!G+0G	y&	'G3# 3%	$(="> 32 2y~s':!; 2 "#"& $:: c]: }	:
 $: ~: 
y~s"	#::@3 @S @ @yPT?T9U @;# ; ;y~s7J1K ;(:# :T :$ :54RVAV;W :3# 3%	$(="> 3:C :c :eIcNC4G.H :r7   r  c                   b    e Zd ZdZdddefdZ	 	 	 ddeee   df   dee	e
   df   d	ed
   fdZy)ScriptI
    An executable Lua script object returned by ``register_script``
    registered_clientr*   scriptc                 &   || _         || _        t        |t              r,	 |j                  j                         }|j                  |      }t        j                  |      j                         | _        y # t        $ r |j                         }Y Uw xY wr~   r  r  rP   r   connection_poolrm   AttributeErrorro   hashlibsha1	hexdigestshar2   r  r  rr   s       r5   r  zScript.__init__  ~    !2 fc":+;;GGI ^^F+F<<'113	 " :+779:   A4 4BBNr`   r:   r  )r*   Nc                    |xs g }|xs g }|| j                   }t        |      t        |      z   }ddlm} t	        ||      r|j
                  j                  |        	  |j                  | j                  t        |      g| S # t        $ rJ |j                  | j                        | _         |j                  | j                  t        |      g| cY S w xY w1Execute the script, passing any required ``args``r   Pipeliner  r  r5  r  rP   scriptsaddevalshar  r   r   script_loadr  r2   r`   r:   r  r  s        r5   __call__zScript.__call__  s     zrzr>++FT{U4[()fh'NNt$	>!6>>$((CI=== 	> ))$++6DH!6>>$((CI===	>s    &B ACCr  r   r   r   r   r$   r  r   r   r"   r	   r   r$  r   r7   r5   r
  r
    sh    4' 4; 4$ -126'+	>HTND()> HZ($./> m$	>r7   r
  c                   b    e Zd ZdZdddefdZ	 	 	 ddeee   df   dee	e
   df   d	ed
   fdZy)AsyncScriptr  r  r  r  c                 &   || _         || _        t        |t              r,	 |j                  j                         }|j                  |      }t        j                  |      j                         | _        y # t        $ r |j                         }Y Uw xY wr~   r  r  s       r5   r  zAsyncScript.__init__  r  r  Nr`   r:   r  )r  Nc                   K   |xs g }|xs g }|| j                   }t        |      t        |      z   }ddlm} t	        ||      r|j
                  j                  |        	  |j                  | j                  t        |      g|  d{   S 7 # t        $ r\ |j                  | j                         d{  7  | _         |j                  | j                  t        |      g|  d{  7  cY S w xY ww)r  Nr   r  )r  r  redis.asyncio.clientr  rP   r  r   r!  r  r   r   r"  r  r#  s        r5   r$  zAsyncScript.__call__  s      zrzr>++FT{U4[(1fh'NNt$	D'#d)CdCCCC 	D $//<<<DH'#d)CdCCCC	DsT   AC;"*B BB C;B 'C8:B=;4C8/C20C85C;7C88C;r  r%  r   r7   r5   r'  r'  	  sm    4, 4 4$ -126,0	DHTND()D HZ($./D ()	Dr7   r'  c                       e Zd ZdZdededefdZdededefdZdde	defd	Z
dde	defd
ZdefdZdedefdZdedefdZy)PubSubCommandszG
    Redis PubSub commands.
    see https://redis.io/topics/pubsub
    rx   messager.   c                 ,     | j                   d||fi |S )z
        Publish ``message`` on ``channel``.
        Returns the number of subscribers the message was delivered to.

        For more information see https://redis.io/commands/publish
        PUBLISHr0   )r2   rx   r-  r3   s       r5   publishzPubSubCommands.publish@  s      $t##IwJ6JJr7   shard_channelc                 (    | j                  d||      S )z
        Posts a message to the given shard channel.
        Returns the number of clients that received the message

        For more information see https://redis.io/commands/spublish
        SPUBLISHr0   )r2   r1  r-  s      r5   spublishzPubSubCommands.spublishI  s     ##JwGGr7   r  c                 *     | j                   d|fi |S )z
        Return a list of channels that have at least one subscriber

        For more information see https://redis.io/commands/pubsub-channels
        zPUBSUB CHANNELSr0   rm  s      r5   pubsub_channelszPubSubCommands.pubsub_channelsR  s     $t##$5wI&IIr7   c                 *     | j                   d|fi |S )z
        Return a list of shard_channels that have at least one subscriber

        For more information see https://redis.io/commands/pubsub-shardchannels
        zPUBSUB SHARDCHANNELSr0   rm  s      r5   pubsub_shardchannelsz#PubSubCommands.pubsub_shardchannelsZ  s     $t##$:GNvNNr7   c                 &     | j                   di |S )z
        Returns the number of subscriptions to patterns

        For more information see https://redis.io/commands/pubsub-numpat
        )zPUBSUB NUMPATr0   rH   s     r5   pubsub_numpatzPubSubCommands.pubsub_numpatb  r  r7   r:   c                 .     | j                   dg|i |S )z
        Return a list of (channel, number of subscribers) tuples
        for each channel given in ``*args``

        For more information see https://redis.io/commands/pubsub-numsub
        zPUBSUB NUMSUBr0   r  s      r5   pubsub_numsubzPubSubCommands.pubsub_numsubj  s!     $t##OEdEfEEr7   c                 .     | j                   dg|i |S )z
        Return a list of (shard_channel, number of subscribers) tuples
        for each channel given in ``*args``

        For more information see https://redis.io/commands/pubsub-shardnumsub
        zPUBSUB SHARDNUMSUBr0   r  s      r5   pubsub_shardnumsubz!PubSubCommands.pubsub_shardnumsubs  s"     $t##$8J4J6JJr7   Nr  )r   r   r   r   r   r   r   r0  r4  r#   r6  r8  r:  r<  r>  r   r7   r5   r,  r,  :  s    
Kx K* K9 KHh H H	 HJx JI JOH O O? ?F8 F) FK Ky Kr7   r,  c                   z   e Zd ZdZdededededeee   ef   f
dZ	dedededeee   ef   fdZ
dedededeee   ef   fd	Zded
edededeee   ef   f
dZd
edededeee   ef   fdZd
edededeee   ef   fdZdedefdZddZ	 ddeed   ed   f   defdZdefdZdedefdZdddedefdZy)ScriptCommandsz|
    Redis Lua script commands. see:
    https://redis.com/ebook/part-3-next-steps/chapter-11-scripting-redis-with-lua/
    r   r  r  keys_and_argsr.   c                 ,     | j                   |||g| S r~   r0   )r2   r   r  r  rA  s        r5   _evalzScriptCommands._eval  s      $t##GVWM}MMr7   c                 ,     | j                   d||g| S )a  
        Execute the Lua ``script``, specifying the ``numkeys`` the script
        will touch and the key names and argument values in ``keys_and_args``.
        Returns the result of the script.

        In practice, use the object returned by ``register_script``. This
        function exists purely for Redis API completion.

        For more information see  https://redis.io/commands/eval
        EVALrC  r2   r  r  rA  s       r5   evalzScriptCommands.eval  s     tzz&&'BMBBr7   c                 ,     | j                   d||g| S )aM  
        The read-only variant of the EVAL command

        Execute the read-only Lua ``script`` specifying the ``numkeys`` the script
        will touch and the key names and argument values in ``keys_and_args``.
        Returns the result of the script.

        For more information see  https://redis.io/commands/eval_ro
        EVAL_ROrF  rG  s       r5   eval_rozScriptCommands.eval_ro  s     tzz)VWE}EEr7   r  c                 ,     | j                   |||g| S r~   r0   )r2   r   r  r  rA  s        r5   _evalshazScriptCommands._evalsha  s      $t##GS'JMJJr7   c                 ,     | j                   d||g| S )a  
        Use the ``sha`` to execute a Lua script already registered via EVAL
        or SCRIPT LOAD. Specify the ``numkeys`` the script will touch and the
        key names and argument values in ``keys_and_args``. Returns the result
        of the script.

        In practice, use the object returned by ``register_script``. This
        function exists purely for Redis API completion.

        For more information see  https://redis.io/commands/evalsha
        EVALSHArM  r2   r  r  rA  s       r5   r!  zScriptCommands.evalsha  s     t}}YWE}EEr7   c                 ,     | j                   d||g| S )a  
        The read-only variant of the EVALSHA command

        Use the ``sha`` to execute a read-only Lua script already registered via EVAL
        or SCRIPT LOAD. Specify the ``numkeys`` the script will touch and the
        key names and argument values in ``keys_and_args``. Returns the result
        of the script.

        For more information see  https://redis.io/commands/evalsha_ro
        
EVALSHA_ROrP  rQ  s       r5   
evalsha_rozScriptCommands.evalsha_ro  s     t}}\3H-HHr7   r:   c                 (     | j                   dg| S )a'  
        Check if a script exists in the script cache by specifying the SHAs of
        each script as ``args``. Returns a list of boolean values indicating if
        if each already script exists in the cache.

        For more information see  https://redis.io/commands/script-exists
        zSCRIPT EXISTSr0   r  s     r5   script_existszScriptCommands.script_exists  s     $t##O;d;;r7   Nc                     t        d      )Nz<SCRIPT DEBUG is intentionally not implemented in the client.r   r  s     r5   script_debugzScriptCommands.script_debug  r   r7   	sync_typer3  ASYNCc                 V    |dvrt        d      |g }n|g} | j                  dg| S )zFlush all scripts from the script cache.

        ``sync_type`` is by default SYNC (synchronous) but it can also be
                      ASYNC.

        For more information see  https://redis.io/commands/script-flush
        )r3  rZ  NzpSCRIPT FLUSH defaults to SYNC in redis > 6.2, or accepts SYNC/ASYNC. For older versions, of redis leave as None.zSCRIPT FLUSHr   )r2   rY  r4   s      r5   script_flushzScriptCommands.script_flush  sK     33* 
 F[F#t##N<V<<r7   c                 $    | j                  d      S )z
        Kill the currently executing Lua script

        For more information see https://redis.io/commands/script-kill
        zSCRIPT KILLr0   r   s    r5   script_killzScriptCommands.script_kill  s     ##M22r7   c                 &    | j                  d|      S )z
        Load a Lua ``script`` into the script cache. Returns the SHA.

        For more information see https://redis.io/commands/script-load
        zSCRIPT LOADr0   r2   r  s     r5   r"  zScriptCommands.script_load  s     ##M6::r7   r2   r*   c                     t        | |      S a  
        Register a Lua ``script`` specifying the ``keys`` it will touch.
        Returns a Script object that is callable and hides the complexity of
        deal with scripts, keys, and shas. This is the preferred way to work
        with Lua scripts.
        )r
  r`  s     r5   register_scriptzScriptCommands.register_script  s     dF##r7   r  r~   )r   r   r   r   r   rA   r   r   r   rC  rH  rK  rM  r!  rT  r   rV  rX  r   r\  r^  r$   r"  r
  rc  r   r7   r5   r@  r@    s   
NN$'N25NGKN	y~s"	#N
CC$'C9=C	y~s"	#CFF$'F9=F	y~s"	#FKK!$K/2KDHK	y~s"	#K
FF!$F6:F	y~s"	#F II!$I6:I	y~s"	#I<3 <9 <
 EI=wv0@@A=	=03Y 3;+ ;) ;$g ${ $v $r7   r@  c                   4     e Zd Zd fdZdddedefdZ xZS )AsyncScriptCommandsr.   c                 (   K   t         |          S wr~   )r  rX  )r2   r:   r  s     r5   rX  z AsyncScriptCommands.script_debug       w#%%r  r2   r  r  c                     t        | |      S rb  )r'  r`  s     r5   rc  z#AsyncScriptCommands.register_script  s     4((r7   r  )r   r   r   rX  r$   r'  rc  r  r  s   @r5   re  re    s"    &)l )K )K )r7   re  c                   4   e Zd ZdZ	 	 	 d)dedee   dedededefdZ		 d*ded
e
de
deed	f   def
dZdede
defdZdede
defdZ	 	 	 	 	 	 	 	 	 d+dededededeed	f   dedededeed	f   deed	f   deed	f   deed	f   dedefdZ	 	 	 	 	 	 	 	 	 d+dede
dedeed	f   dedededeed	f   deed	f   deed	f   deed	f   dedefdZdeded eed	f   defd!Z	 	 	 	 	 	 	 	 	 	 	 	 	 d,dedee
d	f   deed	f   deed	f   dedeed	f   d"eed	f   d#eed	f   deed	f   deed	f   dededededefd$Z	 	 	 	 	 	 	 	 	 	 	 d-d%ededee
d	f   deed	f   deed	f   dedeed	f   d"eed	f   d#eed	f   deed	f   deed	f   ded&edefd'Zdeded eed	f   defd(Zy	).GeoCommandszr
    Redis Geospatial commands.
    see: https://redis.com/redis-best-practices/indexing-patterns/geospatial/
    r   r9  r)  r*  rE  r.   c                    |r|rt        d      t        |      dz  dk7  rt        d      |g}|r|j                  d       |r|j                  d       |r|j                  d       |j                  |        | j                  dg| S )	aA  
        Add the specified geospatial items to the specified key identified
        by the ``name`` argument. The Geospatial items are given as ordered
        members of the ``values`` argument, each item or place is formed by
        the triad longitude, latitude and name.

        Note: You can use ZREM to remove elements.

        ``nx`` forces ZADD to only create new elements and not to update
        scores for elements that already exist.

        ``xx`` forces ZADD to only update scores of elements that already
        exist. New elements will not be added.

        ``ch`` modifies the return value to be the numbers of elements changed.
        Changed elements include new elements that were added and elements
        whose scores changed.

        For more information see https://redis.io/commands/geoadd
        z+GEOADD allows either 'nx' or 'xx', not both   r   z4GEOADD requires places with lon, lat and name valuesr.  r/  CHGEOADD)r   r   rQ   r   r1   )r2   r   r9  r)  r*  rE  r4   s          r5   geoaddzGeoCommands.geoadd!  s    8 "IJJv;?aRSSMM$MM$MM$f#t##H6v66r7   Nplace1place2unitc                 z    |||g}|r|dvrt        d      |r|j                  |        | j                  dg| S )a  
        Return the distance between ``place1`` and ``place2`` members of the
        ``name`` key.
        The units must be one of the following : m, km mi, ft. By default
        meters are used.

        For more information see https://redis.io/commands/geodist
        mkmmiftzGEODIST invalid unitGEODISTr  )r2   r   rp  rq  rr  r4   s         r5   geodistzGeoCommands.geodistK  sN     %)&&#9D 77233MM$#t##I777r7   c                 *     | j                   d|g| S )z
        Return the geo hash string for each item of ``values`` members of
        the specified key identified by the ``name`` argument.

        For more information see https://redis.io/commands/geohash
        GEOHASHr0   r<  s      r5   geohashzGeoCommands.geohash]  s     $t##It=f==r7   c                 *     | j                   d|g| S )a  
        Return the positions of each item of ``values`` as members of
        the specified key identified by the ``name`` argument. Each position
        is represented by the pairs lon and lat.

        For more information see https://redis.io/commands/geopos
        GEOPOSr0   r<  s      r5   geoposzGeoCommands.geoposf  s     $t##Hd<V<<r7   	longitudelatituderadiuswithdist	withcoordwithhashrM   ro  re  
store_distanyc                 @    | j                  d|||||||||	|
|||      S )a  
        Return the members of the specified key identified by the
        ``name`` argument which are within the borders of the area specified
        with the ``latitude`` and ``longitude`` location and the maximum
        distance from the center specified by the ``radius`` value.

        The units must be one of the following : m, km mi, ft. By default

        ``withdist`` indicates to return the distances of each place.

        ``withcoord`` indicates to return the latitude and longitude of
        each place.

        ``withhash`` indicates to return the geohash string of each place.

        ``count`` indicates to return the number of elements up to N.

        ``sort`` indicates to return the places in a sorted way, ASC for
        nearest to fairest and DESC for fairest to nearest.

        ``store`` indicates to save the places names in a sorted set named
        with a specific key, each element of the destination sorted set is
        populated with the score got from the original geo sorted set.

        ``store_dist`` indicates to save the places names in a sorted set
        named with a specific key, instead of ``store`` the sorted set
        destination score is set with the distance.

        For more information see https://redis.io/commands/georadius
        	GEORADIUS	rr  r  r  r  rM   ro  re  r  r  _georadiusgeneric)r2   r   r  r  r  rr  r  r  r  rM   ro  re  r  r  s                 r5   	georadiuszGeoCommands.georadiusp  sG    \ %%! & 
 	
r7   memberc                 >    | j                  d|||||||||	|
||      S )a  
        This command is exactly like ``georadius`` with the sole difference
        that instead of taking, as the center of the area to query, a longitude
        and latitude value, it takes the name of a member already existing
        inside the geospatial index represented by the sorted set.

        For more information see https://redis.io/commands/georadiusbymember
        GEORADIUSBYMEMBERr  r  )r2   r   r  r  rr  r  r  r  rM   ro  re  r  r  s                r5   georadiusbymemberzGeoCommands.georadiusbymember  sC    . %%! & 
 	
r7   r   r:   r3   c                    t        |      }|d   r|d   dvrt        d      |d   r|j                  |d          n|j                  d       |d   r|d   t        d      dD ]  \  }}||   s|j                  |        |d   ,|j                  d	|d   g       |d   r|j                  d
       |d   r?|d   dk(  r|j                  d       n%|d   dk(  r|j                  d       nt        d      |d   r|d   rt        d      |d   r|j                  d|d   g       |d   r|j                  d|d   g        | j                  |g|i |S )Nrr  rt  zGEORADIUS invalid unitru  r  rM   z+``any`` can't be provided without ``count``))r  WITHDIST)r  	WITHCOORD)r  WITHHASHr"  ANYro  ASCDESCzGEORADIUS invalid sortre  r  z3GEORADIUS store and store_dist cant be set togetherrk  	   STOREDIST)r   r   rQ   r   r1   r2   r   r:   r3   r4   arg_name	byte_reprs          r5   r  zGeoCommands._georadiusgeneric  s    d&>fVn4KK455F^MM&.)MM#%=VG_4IJJ$
 	)Hi
 hi(	) '?&MM7F7O45e}e$&>f~&e$6)f% 899'?vl3QRR'?MM8VG_56,MM<)=>?#t##G?f???r7   widthheightc                 F    | j                  d|||||||||	|
||||dd      S )aR  
        Return the members of specified key identified by the
        ``name`` argument, which are within the borders of the
        area specified by a given shape. This command extends the
        GEORADIUS command, so in addition to searching within circular
        areas, it supports searching within rectangular areas.

        This command should be used in place of the deprecated
        GEORADIUS and GEORADIUSBYMEMBER commands.

        ``member`` Use the position of the given existing
         member in the sorted set. Can't be given with ``longitude``
         and ``latitude``.

        ``longitude`` and ``latitude`` Use the position given by
        this coordinates. Can't be given with ``member``
        ``radius`` Similar to GEORADIUS, search inside circular
        area according the given radius. Can't be given with
        ``height`` and ``width``.
        ``height`` and ``width`` Search inside an axis-aligned
        rectangle, determined by the given height and width.
        Can't be given with ``radius``

        ``unit`` must be one of the following : m, km, mi, ft.
        `m` for meters (the default value), `km` for kilometers,
        `mi` for miles and `ft` for feet.

        ``sort`` indicates to return the places in a sorted way,
        ASC for nearest to furthest and DESC for furthest to nearest.

        ``count`` limit the results to the first count matching items.

        ``any`` is set to True, the command will return as soon as
        enough matches are found. Can't be provided without ``count``

        ``withdist`` indicates to return the distances of each place.
        ``withcoord`` indicates to return the latitude and longitude of
        each place.

        ``withhash`` indicates to return the geohash string of each place.

        For more information see https://redis.io/commands/geosearch
        	GEOSEARCHNr  r  r  rr  r  r  r  ro  rM   r  r  r  r  re  r  _geosearchgeneric)r2   r   r  r  r  rr  r  r  r  ro  rM   r  r  r  r  s                  r5   	geosearchzGeoCommands.geosearch  sP    z %%# & 
 	
r7   r  	storedistc                 H    | j                  d|||||||||	|
||dddd|      S )a  
        This command is like GEOSEARCH, but stores the result in
        ``dest``. By default, it stores the results in the destination
        sorted set with their geospatial information.
        if ``store_dist`` set to True, the command will stores the
        items in a sorted set populated with their distance from the
        center of the circle or box, as a floating-point number.

        For more information see https://redis.io/commands/geosearchstore
        GEOSEARCHSTORENr  r  )r2   r  r   r  r  r  rr  r  r  r  ro  rM   r  r  s                 r5   geosearchstorezGeoCommands.geosearchstoreU  sR    4 %% % & 
 	
r7   c                    t        |      }|d   |d   |d   t        d      |d   r+|d   s|d   rt        d      |j                  d|d   g       |d   |d   |j                  d|d   |d   g       |d   |d	   |d
   t        d      |d   t        d      |d   j                         dvrt        d      |d   r/|d	   s|d
   rt        d      |j                  d|d   |d   g       |d	   r#|d
   r|j                  d|d	   |d
   |d   g       |d   r[|d   j	                         dk(  r|j                  d       n3|d   j	                         dk(  r|j                  d       nt        d      |d   r-|j                  d|d   g       |d   r"|j                  d       n|d   rt        d      dD ]  \  }}||   s|j                  |         | j                  |g|i |S )Nr  r  r  z4GEOSEARCH must have member or longitude and latitudez?GEOSEARCH member and longitude or latitude cant be set togethers
   FROMMEMBERs
   FROMLONLATr  r  r  z.GEOSEARCH must have radius or width and heightrr  zGEOSEARCH must have unitrt  zGEOSEARCH invalid unitz9GEOSEARCH radius and width or height cant be set togethers   BYRADIUSs   BYBOXro  r  s   ASCr  rj  zGEOSEARCH invalid sortrM   ry  r  s   ANYz1GEOSEARCH ``any`` can't be provided without count))r  s   WITHDIST)r  s	   WITHCOORD)r  s   WITHHASH)r  r  )r   r   r   r   r  rQ   r1   r  s          r5   r  zGeoCommands._geosearchgeneric  sk    d (#k"*fZ.@.H VWW(k"fZ&8U  MM=&*:;<+*vj/A/MMM=&*=vj?QRS (#g&&*:*B PQQ&>!677&>!)@@455(g&"2O  MM;x(8&.IJ'?vh/MM8VG_fX6FvWX &>f~##%.f%%%'61g& 899 '?MM8VG_56e}f%E]OPP$
 	)Hi hi(	) $t##G?f???r7   )FFFr~   )	NFFFNNNNF)NNNru  NNNNNFFFF)NNNru  NNNNNFF)r   r   r   r   r"   r   r   r   r   ro  r   r   r   rz  r}  r  r  rA   r  r  r  r  r  r  r   r7   r5   rj  rj    s    (7(7 $(7 	(7
 (7 (7 
(7V TX88"(8288@Ec4i@P8	8$>D >6 >i >=4 =& =Y =  "&"&!%#'(,=
=
 =
 	=

 =
 CI=
 =
 =
 =
 S$Y=
 CI=
 T4Z =
 $*%=
 =
 
=
H "&"&!%#'(,%
%
 %
 	%

 CI%
 %
 %
 %
 S$Y%
 CI%
 T4Z %
 $*%%
 %
 
%
N,@,@#-,@9>z4?O9P,@	,@b '+(,'+%)$(%)!%"&O
O
 fdl#O
 %	O

 t$O
 O
 eTk"O
 UD[!O
 eTk"O
 CIO
 S$YO
 O
 O
 O
 O
  
!O
j '+(,'+%)$(%)!%"&-
-
 -
 fdl#	-

 %-
 t$-
 -
 eTk"-
 UD[!-
 eTk"-
 CI-
 S$Y-
 -
 -
 
-
^>@>@#->@9>z4?O9P>@	>@r7   rj  c            	           e Zd ZdZdefdZ	 	 ddedeee      deee      defdZ	defd	Z
defd
ZddZdefdZdefdZdefdZy)ModuleCommandszO
    Redis Module commands.
    see: https://redis.io/topics/modules-intro
    r.   c                 *     | j                   d|g| S )z
        Loads the module from ``path``.
        Passes all ``*args`` to the module, during loading.
        Raises ``ModuleError`` if a module is not found at ``path``.

        For more information see https://redis.io/commands/module-load
        zMODULE LOADr0   )r2   pathr:   s      r5   module_loadzModuleCommands.module_load  s     $t##M4?$??r7   Nr  r7  r:   c                     g }|"|j                  d       |j                  |       |"|j                  d       |j                  |        | j                  d|g| S )z
        Loads a module from a dynamic library at runtime with configuration directives.

        For more information see https://redis.io/commands/module-loadex
        CONFIGARGSzMODULE LOADEXr  )r2   r  r7  r:   r4   s        r5   module_loadexzModuleCommands.module_loadex  s_     MM(#MM'"MM&!MM$#t##OTCFCCr7   c                 &    | j                  d|      S )z
        Unloads the module ``name``.
        Raises ``ModuleError`` if ``name`` is not in loaded modules.

        For more information see https://redis.io/commands/module-unload
        zMODULE UNLOADr0   r   s     r5   module_unloadzModuleCommands.module_unload  s     ##OT::r7   c                 $    | j                  d      S )z
        Returns a list of dictionaries containing the name and version of
        all loaded modules.

        For more information see https://redis.io/commands/module-list
        zMODULE LISTr0   r   s    r5   module_listzModuleCommands.module_list  s     ##M22r7   c                     t        d      r   r   r   s    r5   r   zModuleCommands.command_info  r   r7   c                 $    | j                  d      S )Nr  r0   r   s    r5   r  zModuleCommands.command_count  s    ##O44r7   c                 (     | j                   dg| S )NzCOMMAND GETKEYSr0   r  s     r5   command_getkeyszModuleCommands.command_getkeys  s    #t##$5===r7   c                 $    | j                  d      S )Nr   r0   r   s    r5   r   zModuleCommands.command
  s    ##I..r7   r  r  )r   r   r   r   r   r  r   r   r   r  r  r  r   r  r  r   r   r7   r5   r  r    s    
@) @ (,$(	DD $s)$D tCy!	D
 
D*;Y ;3Y 3

5y 5>	 >/ /r7   r  c                   *    e Zd ZdZd Zg g dfdZd Zy)r
  r  c                     || _         || _        t        |t              r!| j	                         }|j                  |      }t        j                  |      j                         | _	        y r~   )
r  r  rP   r   rm   ro   r  r  r  r  r  s       r5   r  zScript.__init__  sT    !2 fc" &&(G^^F+F<<'113r7   Nc                    || j                   }t        |      t        |      z   }ddlm} t	        ||      r|j
                  j                  |        	  |j                  | j                  t        |      g| S # t        $ rJ |j                  | j                        | _         |j                  | j                  t        |      g| cY S w xY wr  r  r#  s        r5   r$  zScript.__call__  s    >++FT{U4[()fh'NNt$	>!6>>$((CI=== 	> ))$++6DH!6>>$((CI===	>s   &A; ;ACCc                     	 | j                   j                         S # t        $ r' | j                   j                  j                         cY S w xY w)z4Get the encoder to encode string scripts into bytes.)r  rm   r  r  r   s    r5   rm   zScript.get_encoder3  sK    	H))5577 	H ))99EEGG	Hs    -AA)r   r   r   r   r  r$  rm   r   r7   r5   r
  r
    s     
4 R >(Hr7   c                         e Zd Zd fdZ xZS )AsyncModuleCommandsc                 (   K   t         |          S wr~   r  r  s    r5   r   z AsyncModuleCommands.command_infoG  rg  r  r  )r   r   r   r   r  r  s   @r5   r  r  F  s    & &r7   r  c                   4    e Zd ZdZdefdZdefdZdefdZy)ClusterCommandsz*
    Class for Redis Cluster commands
    r.   c                 P     | j                   d|j                          g|i |S )NzCLUSTER )r1   r  )r2   cluster_argr:   r3   s       r5   clusterzClusterCommands.clusterP  s0    #t##h{/@/@/B.C$DVtVvVVr7   c                 &     | j                   di |S )z
        Disables read queries for a connection to a Redis Cluster slave node.

        For more information see https://redis.io/commands/readwrite
        )	READWRITEr0   rH   s     r5   	readwritezClusterCommands.readwriteS  r   r7   c                 &     | j                   di |S )z
        Enables read queries for a connection to a Redis Cluster replica node.

        For more information see https://redis.io/commands/readonly
        )READONLYr0   rH   s     r5   readonlyzClusterCommands.readonly[  rJ   r7   N)r   r   r   r   r   r  r  r  r   r7   r5   r  r  K  s-    Wy W;Y ;:I :r7   r  c            
          e Zd ZdZ	 ddedee   deee   ef   fdZ	dedeee   ef   fdZ
ddedeee   ef   fd	Z	 ddee   d
ee   deee   ef   fdZdededee   deee   ef   fdZdedee   deee   ef   fdZdedee   deee   ef   fdZdeee   ef   fdZ	 ddedee   deee   ef   fdZdeee   ef   fdZdeee   ef   fdZy)FunctionCommandsz!
    Redis Function commands
    coder]  r.   c                 X    |rdgng }|j                  |        | j                  dg| S )a  
        Load a library to Redis.
        :param code: the source code (must start with
        Shebang statement that provides a metadata about the library)
        :param replace: changes the behavior to overwrite the existing library
        with the new contents.
        Return the library name that was loaded.

        For more information see https://redis.io/commands/function-load
        r  zFUNCTION LOADr   )r2   r  r]  r4   s       r5   function_loadzFunctionCommands.function_loadl  s3     !()Rd#t##O=f==r7   libraryc                 &    | j                  d|      S )z
        Delete the library called ``library`` and all its functions.

        For more information see https://redis.io/commands/function-delete
        zFUNCTION DELETEr0   )r2   r  s     r5   function_deletez FunctionCommands.function_delete}  s     ##$5w??r7   r   c                 &    | j                  d|      S )zw
        Deletes all the libraries.

        For more information see https://redis.io/commands/function-flush
        zFUNCTION FLUSHr0   r   s     r5   function_flushzFunctionCommands.function_flush  s     ##$4d;;r7   withcodec                 V    d|g}|r|j                  d        | j                  dg| S )z
        Return information about the functions and libraries.
        :param library: pecify a pattern for matching library names
        :param withcode: cause the server to include the libraries source
         implementation in the reply
        LIBRARYNAMEWITHCODEzFUNCTION LISTr   )r2   r  r  r:   s       r5   function_listzFunctionCommands.function_list  s5     w'KK
##t##O;d;;r7   r   r  rA  c                 ,     | j                   |||g| S r~   r0   )r2   r   functionr  rA  s        r5   _fcallzFunctionCommands._fcall  s      $t##GXwOOOr7   c                 ,     | j                   d||g| S )zf
        Invoke a function.

        For more information see https://redis.io/commands/fcall
        FCALLr  r2   r  r  rA  s       r5   fcallzFunctionCommands.fcall  s     t{{7HgFFFr7   c                 ,     | j                   d||g| S )z
        This is a read-only variant of the FCALL command that cannot
        execute commands that modify data.

        For more information see https://redis.io/commands/fcal_ro
        FCALL_ROr  r  s       r5   fcall_rozFunctionCommands.fcall_ro  s     t{{:xI=IIr7   c                 @    ddl m} i }g ||<    | j                  di |S )z
        Return the serialized payload of loaded libraries.

        For more information see https://redis.io/commands/function-dump
        r   r0  )zFUNCTION DUMPr4  r6  s      r5   function_dumpzFunctionCommands.function_dump  s,     	. "#t##?w??r7   payloadpolicyc                 (    | j                  d||      S )z
        Restore libraries from the serialized ``payload``.
        You can use the optional policy argument to provide a policy
        for handling existing libraries.

        For more information see https://redis.io/commands/function-restore
        zFUNCTION RESTOREr0   )r2   r  r  s      r5   function_restorez!FunctionCommands.function_restore  s     ##$6HHr7   c                 $    | j                  d      S )z
        Kill a function that is currently executing.

        For more information see https://redis.io/commands/function-kill
        zFUNCTION KILLr0   r   s    r5   function_killzFunctionCommands.function_kill  s     ##O44r7   c                 $    | j                  d      S )z
        Return information about the function that's currently running
        and information about the available execution engines.

        For more information see https://redis.io/commands/function-stats
        zFUNCTION STATSr0   r   s    r5   function_statszFunctionCommands.function_stats  s     ##$455r7   Nr  r2  )r  F)r  )r   r   r   r   r   r   r   r   r   r  r  r  r   r  rA   r  r  r  r  r  r  r  r   r7   r5   r  r  g  s   
 49>>"*4.>	y~s"	#>"@s @uYs^S5H/I @<3 <E)C.#:M4N < HM<}<6>tn<	y$	%<PP/2PDLTNP	y~s"	#P
G!$G6>tnG	y~s"	#G	J!$	J6>tn	J	y~s"	#	J@uYs^S%89 @ 5=
I
I$,SM
I	y~s"	#
I5uYs^S%89 56iot&; < 6r7   r  c                       e Zd Z	 ddededeedf   defdZdedefdZ	 	 	 dd	ed
e	deedf   defdZ
	 	 ddedededededefdZ	 ddededededef
dZ	 ddededededef
dZy)GearsCommandsNlib_coder]  configr.   c                     g }|r|j                  d       ||j                  d|g       |j                  |        | j                  dg| S )a2  
        Load a new library to RedisGears.

        ``lib_code`` - the library code.
        ``config`` - a string representation of a JSON object
        that will be provided to the library on load time,
        for more information refer to
        https://github.com/RedisGears/RedisGears/blob/master/docs/function_advance_topics.md#library-configuration
        ``replace`` - an optional argument, instructs RedisGears to replace the
        function if its already exists

        For more information see https://redis.io/commands/tfunction-load/
        r  r  zTFUNCTION LOADr  )r2   r  r]  r  r4   s        r5   tfunction_loadzGearsCommands.tfunction_load  sT      MM)$MM8V,-h#t##$4>v>>r7   lib_namec                 &    | j                  d|      S )z
        Delete a library from RedisGears.

        ``lib_name`` the library name to delete.

        For more information see https://redis.io/commands/tfunction-delete/
        zTFUNCTION DELETEr0   )r2   r  s     r5   tfunction_deletezGearsCommands.tfunction_delete  s     ##$6AAr7   	with_codeverbosec                     g }|r|j                  d       |dk\  r|dk  r|j                  d|z         nt        d      |"|j                  d       |j                  |        | j                  dg| S )a  
        List the functions with additional information about each function.

        ``with_code`` Show libraries code.
        ``verbose`` output verbosity level, higher number will increase verbosity level
        ``lib_name`` specifying a library name (can be used multiple times to show multiple libraries in a single command) # noqa

        For more information see https://redis.io/commands/tfunction-list/
        r  r(   rl  vzverbose can be 1, 2 or 3LIBRARYzTFUNCTION LISTr  )r2   r  r  r  r4   s        r5   tfunction_listzGearsCommands.tfunction_list  sx     MM*%a<GqLMM#-(677MM)$MM(##t##$4>v>>r7   	func_namer`   _asyncr:   c                    | d| g}|,|j                  t        |             |j                  |       n|j                  d       ||j                  |       |r | j                  dg| S  | j                  dg| S )N.r   TFCALLASYNCTFCALL)rQ   r   r   r1   )r2   r  r  r`   r  r:   r4   s          r5   _tfcallzGearsCommands._tfcall"  s     Ja	{+,MM#d)$MM$MM!MM$'4''???#t##H6v66r7   c                 .     | j                   |||dg| S )a\  
        Invoke a function.

        ``lib_name`` - the library name contains the function.
        ``func_name`` - the function name to run.
        ``keys`` - the keys that will be touched by the function.
        ``args`` - Additional argument to pass to the function.

        For more information see https://redis.io/commands/tfcall/
        Fr  r2   r  r  r`   r:   s        r5   tfcallzGearsCommands.tfcall6  s     " t||HiuDtDDr7   c                 .     | j                   |||dg| S )ao  
        Invoke an async function (coroutine).

        ``lib_name`` - the library name contains the function.
        ``func_name`` - the function name to run.
        ``keys`` - the keys that will be touched by the function.
        ``args`` - Additional argument to pass to the function.

        For more information see https://redis.io/commands/tfcall/
        Tr
  r  s        r5   tfcall_asynczGearsCommands.tfcall_asyncI  s     " t||HitCdCCr7   )FN)Fr   Nr  r~   )r   r   r   r   r   r   r   r  r  rA   r  r!   r   r  r  r  r   r7   r5   r  r    sP   OS??&*?<A#t)<L?	?0B B B  %)	?? ? T	"	?
 
?@ 77 7 	7
 7 7 
70 	EE E 	E
 E 
E. 	DD D 	D
 D 
Dr7   r  c                       e Zd ZdZy)DataAccessCommandsz
    A class containing all of the implemented data access redis commands.
    This class is to be used as a mixin for synchronous Redis clients.
    Nr   r   r   r   r   r7   r5   r  r  `      r7   r  c                       e Zd ZdZy)AsyncDataAccessCommandsz
    A class containing all of the implemented data access redis commands.
    This class is to be used as a mixin for asynchronous Redis clients.
    Nr  r   r7   r5   r  r  q  r  r7   r  c                       e Zd ZdZy)CoreCommandsz
    A class containing all of the implemented redis commands. This class is
    to be used as a mixin for synchronous Redis clients.
    Nr  r   r7   r5   r  r    r  r7   r  c                       e Zd ZdZy)AsyncCoreCommandsz
    A class containing all of the implemented redis commands. This class is
    to be used as a mixin for asynchronous Redis clients.
    Nr  r   r7   r5   r  r    r  r7   r  )\r4  r  r  typingr   r   r   r   r   r   r	   r
   r   r   r   r   r   r   r   redis.compatr   redis.exceptionsr   r   r   r   redis.typingr   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   helpersr)   r*  r*   r  r5  r   r,   AsyncACLCommandsr   r  r  r  r  r  AsyncListCommandsrt  r  r  AsyncSetCommandsr  AsyncStreamCommandsrD  AsyncSortedSetCommandsr  AsyncHyperlogCommandsr  AsyncHashCommandsr
  r'  r,  AsyncPubSubCommandsr@  re  rj  AsyncGeoCommandsr  r  r  AsyncClusterCommandsr  AsyncFunctionCommandsr  AsyncGearsCommandsr  r  r  r  r   r7   r5   <module>r*     s         $ ! R R    ( "8")S.!	T<" T<n
  [
) [
| - 0;0 0;fm5 m5`]4' ]4@!, !(]
# ]
@ ! O# Ode ePo@" o@d  W	<% W	<t % S8( S8l + ?' ?@ ) ^:# ^:B ! .> .>b.D .Db@K% @KF % J$% J$Z). )g@" g@T  C/% C/L5H 5Hp&. &
:& :2 ' v6 v6r ) wD wDt # """r7   