HEX
Server: LiteSpeed
System: Linux ws4.angoweb.net 5.14.0-611.13.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 11 04:57:59 EST 2025 x86_64
User: tswangoe (2287)
PHP: 8.1.33
Disabled: show_source, system, shell_exec, passthru, exec, phpinfo, popen, proc_open
Upload Files
File: //usr/lib/python3.9/site-packages/redis/commands/__pycache__/core.cpython-39.pyc
a

��b�>�@s:ddlZddlZddlZddlZddlmZmZmZmZm	Z	m
Z
mZmZm
Z
mZmZmZmZmZddlmZddlmZmZmZmZddlmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+ddl,m-Z-er�ddl.m/Z0ddl1m/Z/eeefZ2Gd	d
�d
e�Z3e3Z4Gdd�de�Z5e5Z6Gd
d�de5�Z6Gdd�d�Z7Gdd�de�Z8Gdd�de8�Z9Gdd�de�Z:e:Z;Gdd�de�Z<Gdd�de<�Z=Gdd�de�Z>e>Z?Gdd�de�Z@e@ZAGdd �d e�ZBeBZCGd!d"�d"e�ZDeDZEGd#d$�d$e�ZFeFZGGd%d&�d&�ZHGd'd(�d(�ZIGd)d*�d*e�ZJeJZKGd+d,�d,e�ZLGd-d.�d.eL�ZMGd/d0�d0e�ZNeNZOGd1d2�d2e�ZPGd3d&�d&�ZHGd4d5�d5eP�ZQGd6d7�d7e�ZReRZSGd8d9�d9�ZTeTZUGd:d;�d;e8eDeFeNe:e<e>e@eB�ZVGd<d=�d=e9eEeGeOe;e=e?eAeC�ZWGd>d?�d?e3eReVe5ePeJeLeT�
ZXGd@dA�dAe4eSeWe6eQeKeMeU�
ZYdS)B�N)�
TYPE_CHECKING�Any�
AsyncIterator�	Awaitable�Callable�Dict�Iterable�Iterator�List�Mapping�Optional�Sequence�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@s^eZdZdZd&eedfed�dd�Zdd�Zeed�d	d
�Z	d'ee
dfed�dd
�Zeed�dd�Zed�dd�Z
ed�dd�Zd(ee
dfed�dd�Zed�dd�Zed�dd�Zed�dd�Zd)eeeeeeedfeeeedfeeeeeeeeeeeeeeeeefeeeed�d d!�Zed�d"d#�Zed�d$d%�ZdS)*�ACLCommandszX
    Redis Access Control List (ACL) commands.
    see: https://redis.io/topics/acl
    N)�category�returncKs&|r
|gng}|jdg|�Ri|��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
        zACL CAT��execute_command)�selfr*�kwargs�pieces�r1�7/usr/lib/python3.9/site-packages/redis/commands/core.py�acl_cat=s
zACLCommands.acl_catcOs|jd|g|�Ri|��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 DRYRUNr,)r.�username�argsr/r1r1r2�
acl_dryrunJszACLCommands.acl_dryrun)r4r+cOs|jdg|�Ri|��S)z�
        Delete the ACL for the specified ``username``s

        For more information see https://redis.io/commands/acl-deluser
        zACL DELUSERr,�r.r4r/r1r1r2�acl_deluserRszACLCommands.acl_deluser)�bitsr+cKs`g}|durHz t|�}|dks&|dkr*t�WntyFtd��Yn0|jdg|�Ri|��S)z�Generate 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
        Nriz?genpass optionally accepts a bits argument, between 0 and 4096.zACL GENPASS)�int�
ValueErrorrr-)r.r9r/r0�br1r1r2�acl_genpassZs�
zACLCommands.acl_genpasscKs|jd|fi|��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
        zACL GETUSERr,r7r1r1r2�acl_getuserlszACLCommands.acl_getuser�r+cKs|jdi|��S)z�The ACL HELP command returns helpful text describing
        the different subcommands.

        For more information see https://redis.io/commands/acl-help
        �ACL HELP)r@r,�r.r/r1r1r2�acl_helpvszACLCommands.acl_helpcKs|jdi|��S)z~
        Return a list of all ACLs on the server

        For more information see https://redis.io/commands/acl-list
        �ACL LIST)rCr,rAr1r1r2�acl_list~szACLCommands.acl_list)�countr+cKs@g}|dur(t|t�std��|�|�|jdg|�Ri|��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
        Nz ACL LOG count must be an integer�ACL LOG)�
isinstancer:r�appendr-)r.rEr/r5r1r1r2�acl_log�s

zACLCommands.acl_logcKsdg}|jdg|�Ri|��S)z~
        Reset ACL logs.
        :rtype: Boolean.

        For more information see https://redis.io/commands/acl-log
        sRESETrFr,)r.r/r5r1r1r2�
acl_log_reset�szACLCommands.acl_log_resetcKs|jdi|��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
        �ACL LOAD)rKr,rAr1r1r2�acl_load�s	zACLCommands.acl_loadcKs|jdi|��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
        �ACL SAVE)rMr,rAr1r1r2�acl_save�s	zACLCommands.acl_saveF)r4�enabled�nopass�	passwords�hashed_passwords�
categories�commands�keys�channels�	selectors�reset�
reset_keys�reset_passwordsr+cKs�|��}|g}|r|�d�|r*|�d�|
r8|�d�|rH|�d�n
|�d�|sZ|rf|rftd��|r�t|g�}t|�D]f\}}|�|�}|�d�r�|�d|d	d
��q||�d�r�|�d|d	d
��q|td
|�d���q||�rht|g�}t|�D]j\}}|�|�}|�d��r2|�d|d	d
��q�|�d��rV|�d|d	d
��q�td|�d���q�|�rx|�d�|�r&|D]�}|�|�}|�d��r�|�|�nz|�d��r�|�d|d	d
��nV|�d��r�|�|�n>|�d��r|�d|d	d
��ntd|j|dd��d����q�|�r~|D]L}|�|�}|�d��sp|�d��sptd|j|dd��d���|�|��q0|�r�|D]:}|�|�}|�d��s�|�d��s�d|}|�|��q�|	�r�|	D]}|�|�}|�d|��q�|
�r||
D]�\}}|�|�}|�d��s<|�d��s<td|j|dd��d���|�|�}|�d��sf|�d��sfd|}|�d ||f��q�|jd!g|�Ri|��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_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
        sresets	resetkeyss	resetpasssonsoffz@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!%szHashed password snopasss+@s+@%ss-@s-@%sz
Category "T)�forcez"" must be prefixed with "+" or "-"z	Command "�%�~s~%ss&%ss(%s %s)zACL SETUSER)	�get_encoderrHrr'�	enumerate�encode�
startswith�decoder-)r.r4rOrPrQrRrSrTrUrVrWrXrYrZr/�encoderr0�i�passwordZhashed_passwordr*�cmd�key�channelr1r1r2�acl_setuser�s�N



�




�


�

�
�


�
zACLCommands.acl_setusercKs|jdi|��S)z�Returns a list of all registered users on the server.

        For more information see https://redis.io/commands/acl-users
        �	ACL USERS)rlr,rAr1r1r2�	acl_usersuszACLCommands.acl_userscKs|jdi|��S)z{Get the username for the current connection

        For more information see https://redis.io/commands/acl-whoami
        �
ACL WHOAMI)rnr,rAr1r1r2�
acl_whoami|szACLCommands.acl_whoami)N)N)N)FFNNNNNNNFFF)�__name__�
__module__�__qualname__�__doc__r�str�	ResponseTr3r6r8r:r=r>rBrDrIrJrLrN�boolrrr rrrkrmror1r1r1r2r)7sV


�



�@r)c@sbeZdZdZd�dd�Zdd�Zd�eed�d	d
�Zed�dd
�Z	e
ed�dd�Zd�ee
dfee
dfee
dfeedfeedfe
ed�dd�Z
ed�dd�Zdgfee
dfeeed�dd�Zed�dd�Zed�dd�Zeedededfed �d!d"�Zed�d#d$�Zdgd%d%d%d%feedfeeeeeeed&�d'd(�Zdgd%d%d%d%feedfeeeeeeed&�d)d*�Zddgd%d%d%d%feeedfeeeeeeed+�d,d-�Zed�d.d/�Ze
ed0�d1d2�Zd�eeed3�d4d5�Zd�eeed6�d7d8�Z ed�d9d:�Z!e
ee"e
e
fd;�d<d=�Z#d>d?�Z$dd�d@dA�Z%ed�dBdC�Z&d�e'e
e'e
e'e
edD�dEdF�Z(ee
eee
ee
fdG�dHdI�Z)dJdK�Z*d�e+ee+edM�dNdO�Z,eeeeeefedP�dQdR�Z-ed�dSdT�Z.ed�dUdV�Z/ed�dWdX�Z0eedY�dZd[�Z1dd�d\d]�Z2eed^�d_d`�Z3d�eeda�dbdc�Z4d�eeda�ddde�Z5ed�dfdg�Z6e
edh�didj�Z7eeedk�dldm�Z8eedn�dodp�Z9d�ee
dfee
edq�drds�Z:ed�dtdu�Z;ee
e<fedv�dwdx�Z=ed�dydz�Z>d�e
ee?eeeeee
dfed{�	d|d}�Z@e
eed~�dd��ZAdd�d�d��ZBdd�d�d��ZCed�d�d��ZDed�d�d��ZEd�eeedfed��d�d��ZFed�d�d��ZGd�d��ZHed�d�d��ZIed�d�d��ZJed�d�d��ZKed�d�d��ZLd�eeeeedd��d�d��ZMd�ee
dfeedfed��d�d��ZNd�eedfed��d�d��ZOed�d�d��ZPed�d�d��ZQed�d�d��ZReeed��d�d��ZSd�d��ZTd�d��ZUdS)��ManagementCommandsz#
    Redis management commands
    NcKs8g}|dur|�|�|�|�|jdg|�Ri|��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
        NZAUTH�rHr-)r.rgr4r/r0r1r1r2�auth�s


zManagementCommands.authcKs|jdi|��S)z�Tell the Redis server to rewrite the AOF file from data in memory.

        For more information see https://redis.io/commands/bgrewriteaof
        �BGREWRITEAOF)rzr,rAr1r1r2�bgrewriteaof�szManagementCommands.bgrewriteaofT)�scheduler+cKs*g}|r|�d�|jdg|�Ri|��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
        ZSCHEDULEZBGSAVErx)r.r|r/r0r1r1r2�bgsave�s
zManagementCommands.bgsaver?cCs
|�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
        ZROLEr,�r.r1r1r2�role�szManagementCommands.role)�addressr+cKs|jd|fi|��S)z�Disconnects the client at ``address`` (ip:port)

        For more information see https://redis.io/commands/client-kill
        �CLIENT KILLr,)r.r�r/r1r1r2�client_kill�szManagementCommands.client_kill)�_id�_type�addr�skipme�laddr�userr+c
Ks�g}|dur<d}	t|���|	vr.td|	����|�d|f�|durpt|t�sVtd��|rf|�d�n
|�d�|dur�|�d|f�|dur�|�d	|f�|dur�|�d
|f�|dur�|�d|f�|s�td��|jd
g|�Ri|��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
        N)�normal�masterZslave�pubsubz CLIENT KILL type must be one of �TYPEz!CLIENT KILL skipme must be a bool)�SKIPMEsYES)r��NO�IDsADDRsLADDRsUSERzVCLIENT KILL <filter> <value> ... ... <filter> <value> must specify at least one filterr�)rt�lowerr�extendrGrvr-)
r.r�r�r�r�r�r�r/r5�client_typesr1r1r2�client_kill_filter�s2

�z%ManagementCommands.client_kill_filtercKs|jdi|��S)z�
        Returns information and statistics about the current
        client connection.

        For more information see https://redis.io/commands/client-info
        �CLIENT INFO)r�r,rAr1r1r2�client_info�szManagementCommands.client_info)r��	client_idr+cKs�g}|durBd}t|���|vr.td|����|�d�|�|�t|t�sTtd��|rr|�d�|�d�|��|jdg|�Ri|��S)	aj
        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
        N)r�r�Zreplicar�z!CLIENT LIST _type must be one of r�zclient_id must be a listr�� zCLIENT LIST)rtr�rrHrG�list�joinr-)r.r�r�r/r5r�r1r1r2�client_list�s



zManagementCommands.client_listcKs|jdi|��S)z�
        Returns the current connection name

        For more information see https://redis.io/commands/client-getname
        �CLIENT GETNAME)r�r,rAr1r1r2�client_getnamesz!ManagementCommands.client_getnamecKs|jdi|��S)z�
        Returns the ID (an integer) of the client to whom we are
        redirecting tracking notifications.

        see: https://redis.io/commands/client-getredir
        �CLIENT GETREDIR)r�r,rAr1r1r2�client_getredirsz"ManagementCommands.client_getredir�ON�OFF�SKIP)�replyr+cKs2gd�}||vrtd|����|jd|fi|��S)a�
        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�zCLIENT REPLY must be one of zCLIENT REPLY�rr-)r.r�r/Zrepliesr1r1r2�client_reply#szManagementCommands.client_replycKs|jdi|��S)zy
        Returns the current connection id

        For more information see https://redis.io/commands/client-id
        �	CLIENT ID)r�r,rAr1r1r2r�:szManagementCommands.client_idF)�clientid�prefix�bcast�optin�optout�noloopr+c	Cs|�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�r.r�r�r�r�r�r�r1r1r2�client_tracking_onBs�z%ManagementCommands.client_tracking_onc	Cs|�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�r1r1r2�client_tracking_offUs�z&ManagementCommands.client_tracking_off)�onr�r�r�r�r�r�r+cKs�t|�dkr|durtd��|r&dgndg}	|durB|	�d|g�|D]}
|	�d|
g�qF|rh|	�d	�|rv|	�d
�|r�|	�d�|r�|	�d�|jd
g|	�R�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
        rFz"Prefix can only be used with bcastr�r�NZREDIRECTZPREFIXZBCASTZOPTINZOPTOUTZNOLOOPzCLIENT TRACKING)�lenrr�rHr-)r.r�r�r�r�r�r�r�r/r0�pr1r1r2r�hs )



z"ManagementCommands.client_trackingcKs|jdi|��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
        �CLIENT TRACKINGINFO)r�r,rAr1r1r2�client_trackinginfo�sz&ManagementCommands.client_trackinginfo��namer+cKs|jd|fi|��S)z}
        Sets the current connection name

        For more information see https://redis.io/commands/client-setname
        zCLIENT SETNAMEr,)r.r�r/r1r1r2�client_setname�sz!ManagementCommands.client_setname)r��errorr+cKs*dt|�g}|r|�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
        zCLIENT UNBLOCKsERROR)r:rHr-)r.r�r�r/r5r1r1r2�client_unblock�s
z!ManagementCommands.client_unblock)�timeout�allr+cKs<dt|�g}t|t�std��|s,|�d�|j|i|��S)a�
        Suspend all the Redis clients for the specified amount of time
        :param timeout: milliseconds to pause clients

        For more information see https://redis.io/commands/client-pause
        :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 integerZWRITE)rtrGr:rrHr-)r.r�r�r/r5r1r1r2�client_pause�s

zManagementCommands.client_pausecKs|jdi|��S)zv
        Unpause all redis clients

        For more information see https://redis.io/commands/client-unpause
        �CLIENT UNPAUSE)r�r,rAr1r1r2�client_unpause�sz!ManagementCommands.client_unpause��moder+cCs|�d|�S)z�
        Sets the client eviction mode for the current connection.

        For more information see https://redis.io/commands/client-no-evict
        zCLIENT NO-EVICTr,�r.r�r1r1r2�client_no_evict�sz"ManagementCommands.client_no_evictcKs|jdi|��S)z�
        Returns dict reply of details about all Redis commands.

        For more information see https://redis.io/commands/command
        �COMMAND)r�r,rAr1r1r2�command�szManagementCommands.commandcKstd��dS�Nz<COMMAND INFO is intentionally not implemented in the client.��NotImplementedErrorrAr1r1r2�command_info�s�zManagementCommands.command_infocKs|jdi|��S)N�
COMMAND COUNT)r�r,rAr1r1r2�
command_count�sz ManagementCommands.command_count)�moduler*�patternr+cCshg}|dur|�d|g�|dur0|�d|g�|durF|�d|g�|rV|�dd�|jdg|�R�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/
        NZMODULEZACLCATZPATTERNrZFILTERBYzCOMMAND LIST)r��insertr-)r.r�r*r�r0r1r1r2�command_list�szManagementCommands.command_list�r5r+cGs|jdg|�R�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
        zCOMMAND GETKEYSANDFLAGSr,�r.r5r1r1r2�command_getkeysandflagssz*ManagementCommands.command_getkeysandflagscGstd��dS)�m
        This function throws a NotImplementedError since it is intentionally
        not supported.
        z<COMMAND DOCS is intentionally not implemented in the client.Nr�r�r1r1r2�command_docs s�zManagementCommands.command_docs�*)r�r5r+cOs|jd|g|�Ri|��S)z�
        Return a dictionary of configuration based on the ``pattern``

        For more information see https://redis.io/commands/config-get
        z
CONFIG GETr,)r.r�r5r/r1r1r2�
config_get)szManagementCommands.config_get)r��valuer5r+cOs|jd||g|�Ri|��S)zwSet config item ``name`` with ``value``

        For more information see https://redis.io/commands/config-set
        z
CONFIG SETr,)r.r�r�r5r/r1r1r2�
config_set3szManagementCommands.config_setcKs|jdi|��S)zw
        Reset runtime statistics

        For more information see https://redis.io/commands/config-resetstat
        �CONFIG RESETSTAT)r�r,rAr1r1r2�config_resetstat@sz#ManagementCommands.config_resetstatcKs|jdi|��S)z�
        Rewrite config file with the minimal change to reflect running config.

        For more information see https://redis.io/commands/config-rewrite
        �CONFIG REWRITE)r�r,rAr1r1r2�config_rewriteHsz!ManagementCommands.config_rewritecKs|jdi|��S)z�
        Returns the number of keys in the current database

        For more information see https://redis.io/commands/dbsize
        �DBSIZE)r�r,rAr1r1r2�dbsizePszManagementCommands.dbsize�rir+cKs|jd|fi|��S)z�
        Returns version specific meta information about a given key

        For more information see https://redis.io/commands/debug-object
        zDEBUG OBJECTr,)r.rir/r1r1r2�debug_objectXszManagementCommands.debug_objectcKstd��dS)Nz�
            DEBUG SEGFAULT is intentionally not implemented in the client.

            For more information see https://redis.io/commands/debug-segfault
            r�rAr1r1r2�debug_segfault`s�z!ManagementCommands.debug_segfault)r�r+cKs|jd|fi|��S)zw
        Echo the string back from the server

        For more information see https://redis.io/commands/echo
        ZECHOr,)r.r�r/r1r1r2�echoiszManagementCommands.echo)�asynchronousr+cKs*g}|r|�d�|jdg|�Ri|��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
        �ASYNCZFLUSHALLrx�r.r�r/r5r1r1r2�flushallqs	
zManagementCommands.flushallcKs*g}|r|�d�|jdg|�Ri|��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�ZFLUSHDBrxr�r1r1r2�flushdbs	
zManagementCommands.flushdbcCs(ddlm}i}g||<|jdi|��S)z�
        Initiates a replication stream from the master.

        For more information see https://redis.io/commands/sync
        r��NEVER_DECODE�SYNC)r���redis.clientr�r-�r.r��optionsr1r1r2�sync�szManagementCommands.sync)�
replicationid�offsetcCs.ddlm}i}g||<|jd||fi|��S)z�
        Initiates a replication stream from the master.
        Newer version for `sync`.

        For more information see https://redis.io/commands/sync
        rr�ZPSYNCr�)r.r�r�r�r�r1r1r2�psync�szManagementCommands.psync)�first�secondr+cKs|jd||fi|��S)zg
        Swap two databases

        For more information see https://redis.io/commands/swapdb
        ZSWAPDBr,)r.r�r�r/r1r1r2�swapdb�szManagementCommands.swapdb)�indexr+cKs|jd|fi|��S)zcSelect the Redis logical database at index.

        See: https://redis.io/commands/select
        ZSELECTr,)r.r�r/r1r1r2�select�szManagementCommands.select)�sectionr5r+cOs6|dur|jdi|��S|jd|g|�Ri|��SdS)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
        N�INFO)r�r,)r.r�r5r/r1r1r2�info�szManagementCommands.infocKs|jdi|��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
        �LASTSAVE)r�r,rAr1r1r2�lastsave�szManagementCommands.lastsave)�version_numbersr+cOs0|r|jdg|�Ri|��S|jdi|��SdS)z}
        Get the Redis version and a piece of generative computer art

        See: https://redis.io/commands/lolwut
        zLOLWUT VERSION�LOLWUTN)r�r,)r.r�r/r1r1r2�lolwut�szManagementCommands.lolwutcCs
|�d�S)zuPerform a full reset on the connection's server side contenxt.

        See: https://redis.io/commands/reset
        ZRESETr,r~r1r1r2rX�szManagementCommands.reset)	�host�portrU�destination_dbr��copy�replaceryr+c	Ks�t|g�}|std��g}
|r(|
�d�|r6|
�d�|rN|
�d�|
�|�|
�d�|
�|�|jd||d||g|
�Ri|	��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 keysCOPYsREPLACEsAUTHsKEYSZMIGRATE�)r'rrHr�r-)r.rrrUrr�rrryr/r0r1r1r2�migrate�s(






���zManagementCommands.migrate)�infotyperir+cKs|jd||fd|i|��S)zJ
        Return the encoding, idletime, or refcount about the key
        ZOBJECTrr,)r.rrir/r1r1r2�objects���zManagementCommands.objectcKstd��dS)Nz�
            MEMORY DOCTOR is intentionally not implemented in the client.

            For more information see https://redis.io/commands/memory-doctor
            r�rAr1r1r2�
memory_doctors�z ManagementCommands.memory_doctorcKstd��dS)Nz�
            MEMORY HELP is intentionally not implemented in the client.

            For more information see https://redis.io/commands/memory-help
            r�rAr1r1r2�memory_help$s�zManagementCommands.memory_helpcKs|jdi|��S)z~
        Return a dictionary of memory stats

        For more information see https://redis.io/commands/memory-stats
        �MEMORY STATS)rr,rAr1r1r2�memory_stats-szManagementCommands.memory_statscKs|jdi|��S)z�
        Return an internal statistics report from the memory allocator.

        See: https://redis.io/commands/memory-malloc-stats
        �MEMORY MALLOC-STATS)r
r,rAr1r1r2�memory_malloc_stats5sz&ManagementCommands.memory_malloc_stats)ri�samplesr+cKs6g}t|t�r|�d|g�|jd|g|�Ri|��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
        sSAMPLESzMEMORY USAGE)rGr:r�r-)r.rirr/r5r1r1r2�memory_usage=s

zManagementCommands.memory_usagecKs|jdi|��S)z�
        Attempts to purge dirty pages for reclamation by allocator

        For more information see https://redis.io/commands/memory-purge
        �MEMORY PURGE)rr,rAr1r1r2�memory_purgeOszManagementCommands.memory_purgecGstd��dS)r�zALATENCY HISTOGRAM is intentionally not implemented in the client.Nr�r�r1r1r2�latency_histogramWs�z$ManagementCommands.latency_histogramcKs|jdi|��S)zh
        Ping the Redis server

        For more information see https://redis.io/commands/ping
        �PING)rr,rAr1r1r2�ping`szManagementCommands.pingcKs|jdi|��S)zz
        Ask the server to close the connection.

        For more information see https://redis.io/commands/quit
        �QUIT)rr,rAr1r1r2�quithszManagementCommands.quitcOs|jdg|�Ri|��S)a0
        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
        Z	REPLICAOFr,�r.r5r/r1r1r2�	replicaofps	zManagementCommands.replicaofcKs|jdi|��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
        �SAVE)rr,rAr1r1r2�save{szManagementCommands.save�r�nosave�nowr]�abortr+cKs�|r|rtd��dg}|r$|�d�|r2|�d�|r@|�d�|rN|�d�|r\|�d�z|j|i|��Wnty�YdS0td	��dS)
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.�rrHr-rr�r.rrrr]rr/r5r1r1r2�shutdown�s$




zManagementCommands.shutdown)rrr+cKs6|dur |dur |jdi|��S|jd||fi|��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
        N)�SLAVEOFr�sONEr*r,)r.rrr/r1r1r2�slaveof�s
zManagementCommands.slaveof)�numr+cKsTddlm}dg}|dur$|�|�|���dd�}|durDg||<|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
        rr�zSLOWLOG GETN�decode_responsesFT)r�r�rHZget_connection_kwargs�getr-)r.r,r/r�r5r-r1r1r2�slowlog_get�s
zManagementCommands.slowlog_getcKs|jdi|��S)z�
        Get the number of items in the slowlog

        For more information see https://redis.io/commands/slowlog-len
        �SLOWLOG LEN)r0r,rAr1r1r2�slowlog_len�szManagementCommands.slowlog_lencKs|jdi|��S)z{
        Remove all items in the slowlog

        For more information see https://redis.io/commands/slowlog-reset
        �
SLOWLOG RESET)r2r,rAr1r1r2�
slowlog_reset�sz ManagementCommands.slowlog_resetcKs|jdi|��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
        �TIME)r4r,rAr1r1r2�time�szManagementCommands.time)�num_replicasr�r+cKs|jd||fi|��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
        ZWAITr,)r.r6r�r/r1r1r2�wait�s	zManagementCommands.waitcCstd��dS)r�z5HELLO is intentionally not implemented in the client.Nr�r~r1r1r2�hello�s�zManagementCommands.hellocCstd��dS)r�z8FAILOVER is intentionally not implemented in the client.Nr�r~r1r1r2�failover�s�zManagementCommands.failover)N)T)NNNNNN)F)T)NNN)r�)F)F)N)FFN)N)FFFFF)NN)N)Vrprqrrrsryr{rvrur}rrtr�rr�r�r
rr�r�r�rr�r�r:r
r r�r�r�r�r�r�r�r�rr�r�r�r�rr�r�r�r!r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r��floatr�rXrrrr	r
rrrrrrrrrr)r+r/r1r3r5r7r8r9r1r1r1r2rw�sz


	�




�2
��
�
�
��
��
�<		����$
���
	
��	�
�0			��	��+��		rwcsreZdZdd��fdd�Zdd��fdd�Zdd��fdd�Zdd��fd	d
�Zdeeeeedd�d
d�Z�Z	S)�AsyncManagementCommandsNr?c�st�jfi|��S�N��superr�rA��	__class__r1r2r�sz$AsyncManagementCommands.command_infoc�st�jfi|��Sr<)r>r�rAr?r1r2r�sz&AsyncManagementCommands.debug_segfaultc�st�jfi|��Sr<)r>r	rAr?r1r2r	sz%AsyncManagementCommands.memory_doctorc�st�jfi|��Sr<)r>r
rAr?r1r2r
sz#AsyncManagementCommands.memory_helpFrc�s�|r|rtd��dg}|r$|�d�|r2|�d�|r@|�d�|rN|�d�|r\|�d�z|j|i|��IdHWnty�YdS0td	��dS)
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!rr"r#r$r%Nr&r'r(r1r1r2r)s$




z AsyncManagementCommands.shutdown)FFFFF)
rprqrrr�r�r	r
rvr)�
__classcell__r1r1r?r2r;s"��r;c@s�eZdZdZdedeeedfd�dd�Zdd�Zed	�d
d�Zdee	e
eedfd�d
d�Zee	d�dd�Zee	e
d�dd�Z
edd��Zed�dd�ZdS)�BitFieldOperationz0
    Command builder for BITFIELD commands.
    N�r(�
AsyncRedis)�clientri�default_overflowcCs*||_||_||_g|_d|_|��dS)N�WRAP)rEri�_default_overflow�
operations�_last_overflowrX)r.rErirFr1r1r2�__init__?szBitFieldOperation.__init__cCs"g|_d|_|�|jp|j�dS)zL
        Reset the state of the instance to when it was constructed
        rGN)rIrJ�overflowrHr~r1r1r2rXMszBitFieldOperation.reset)rLcCs,|��}||jkr(||_|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.
        ZOVERFLOW)�upperrJrIrH)r.rLr1r1r2rLUs

zBitFieldOperation.overflow)�fmtr��	incrementrLcCs*|dur|�|�|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.
        N�INCRBY)rLrIrH)r.rNr�rOrLr1r1r2�incrbybs
zBitFieldOperation.incrby)rNr�cCs|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�rIrH)r.rNr�r1r1r2r.|s
zBitFieldOperation.get)rNr�r�cCs|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.
        �SETrS)r.rNr�r�r1r1r2�set�szBitFieldOperation.setcCs$d|jg}|jD]}|�|�q|S)NZBITFIELD)rirIr�)r.rh�opsr1r1r2r��s

zBitFieldOperation.commandr?cCs|j}|��|jj|�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�rXrEr-)r.r�r1r1r2�execute�szBitFieldOperation.execute)N)N)rprqrrrsrrtrKrXrLrr:rQr.rU�propertyr�rurWr1r1r1r2rB:s*�
��
�

rBc
@s`eZdZdZeeed�dd�Zd�eee	dfee	dfe
eed�dd�Zd�ed	eeedfe
d
�dd�Zeeeed
�dd�Zd�ee	ee	dfee	dfe
eed�dd�Zd�eeeedfeed�dd�Zd�ee	ed�dd�ZeZeed�dd�Zed�dd �Zeed!�d"d#�Zeed�d$d%�ZeZd�eeeeeeed&�d'd(�Zd�eeeeeeed)�d*d+�Zee	d,�d-d.�Zeed!�d/d0�Zeed!�d1d2�Z d�eeedfeedfeedfeedfeed3�d4d5�Z!ed�d6d7�Z"ee	ed8�d9d:�Z#ee	e	ed;�d<d=�Z$eeed>�d?d@�Z%d�ee	ed�dAdB�Z&e&Z'd�ee(ed�dDdE�Z)d�e*edG�dHdI�Z+d�eeeeedL�dMdN�Z,d�eee	eeedO�dPdQ�Z-e.eedR�dSdT�Z/e0e1efedU�dVdW�Z2e0e1efedU�dXdY�Z3ee	edZ�d[d\�Z4eed!�d]d^�Z5d�eeeeeeed&�d_d`�Z6d�eeeeeeed)�dadb�Z7ee	d,�dcdd�Z8eeede�dfdg�Z9eed!�dhdi�Z:d�ee	eedj�dkdl�Z;edm�dndo�Z<eeedp�dqdr�Z=eeds�dtdu�Z>d�ee(eeeee	dfee	dfedv�dwdx�Z?d�eeeedfeedfeeeeeedfeedfedy�dzd{�Z@eed|�d}d~�ZAee	e	ed�d�d��ZBeeeed��d�d��ZCeeed>�d�d��ZDee	eed�d�d��ZEd�eFd�eeeeFd�eFd�feeee	dfeed��	d�d��ZGeed!�d�d��ZHd�ee	e	ed��d�d��ZIeed��d�d��ZJeed!�d�d��ZKeed!�d�d��ZLedd�d�d��ZMddm�d�d��ZNeed�d�d��ZOd�eee
ee
ee
e	e
eeee	ePfd��d�d��ZQdS)��BasicKeyCommandsz(
    Redis basic key-based commands
    )rir�r+cCs|�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
        �APPENDr,)r.rir�r1r1r2rH�szBasicKeyCommands.appendN)ri�start�endr�r+cCsx|g}|dur,|dur,|�|�|�|�n(|dur<|dusL|durT|durTtd��|durf|�|�|jdg|�R�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
        Nz$Both start and end must be specifiedZBITCOUNT)rHrr-)r.rir[r\r��paramsr1r1r2�bitcount�s

 
zBasicKeyCommands.bitcountrC)r.rirFr+cCst|||d�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
        )rF)rB)r.rirFr1r1r2�bitfield�szBasicKeyCommands.bitfield)�	operation�destrUr+cGs|jd||g|�R�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
        ZBITOPr,)r.r`rarUr1r1r2�bitop�szBasicKeyCommands.bitop)ri�bitr[r\r�r+cCs�|dvrtd��||g}|duo(|�|�|durF|durF|�|�n|dur^|dur^td��|durp|�|�|jdg|�R�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
        )rr&zbit must be 0 or 1Nz0start argument is not set, when end is specifiedZBITPOS�rrHr-)r.rircr[r\r�r]r1r1r2�bitpos�s
zBasicKeyCommands.bitposF)�source�destinationrrr+cCs>||g}|dur|�d|g�|r,|�d�|jdg|�R�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
        NZDB�REPLACEZCOPY)r�rHr-)r.rfrgrrr]r1r1r2rs
zBasicKeyCommands.copyr&)r��amountr+cCs|�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
        ZDECRBYr,�r.r�rir1r1r2�decrbyszBasicKeyCommands.decrby��namesr+cGs|jdg|�R�S)z@
        Delete one or more keys specified by ``names``
        ZDELr,�r.rmr1r1r2�delete*szBasicKeyCommands.delete�r�cCs|�|�dSr<)ro�r.r�r1r1r2�__delitem__0szBasicKeyCommands.__delitem__r�cCs,ddlm}i}g||<|jd|fi|��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
        rr�ZDUMPr�)r.r�r�r�r1r1r2�dump3szBasicKeyCommands.dumpcGs|jdg|�R�S)z
        Returns the number of ``names`` that exist

        For more information see https://redis.io/commands/exists
        ZEXISTSr,rnr1r1r2�exists@szBasicKeyCommands.exists)r�r5�nx�xx�gt�ltr+cCslt|tj�rt|���}t�}|r,|�d�|r:|�d�|rH|�d�|rV|�d�|jd||g|�R�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�LTZEXPIRE�rG�datetime�	timedeltar:�
total_secondsr�rHr-�r.r�r5rurvrwrx�
exp_optionr1r1r2�expireJs



zBasicKeyCommands.expire)r��whenrurvrwrxr+cCsrt|tj�rtt�|����}t�}|r2|�d�|r@|�d�|rN|�d�|r\|�d�|jd||g|�R�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
        ryrzr{r|ZEXPIREAT)	rGr~r:r5�mktime�	timetupler�rHr-)r.r�r�rurvrwrxr�r1r1r2�expireatos



zBasicKeyCommands.expireatr�cCs|�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
        Z
EXPIRETIMEr,�r.rir1r1r2�
expiretime�szBasicKeyCommands.expiretimecCs|�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
        rRr,rqr1r1r2r.�szBasicKeyCommands.getcCs|�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
        ZGETDELr,rqr1r1r2�getdel�s	zBasicKeyCommands.getdel)r��ex�px�exat�pxat�persistr+cCsd||||h}t|�dks(t|�dkr0|r0td��g}|durh|�d�t|tj�r^t|���}|�|�|dur�|�d�t|tj�r�t|��d�}|�|�|dur�|�d�t|tj�r�t|jd	�}	tt	�
|����|	}|�|�|du�r@|�d
�t|tj��r6t|jd�}
tt	�
|����d|
}|�|�|�rP|�d�|jd|g|�R�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.N�EX�PX���EXAT�@B�PXAT�PERSISTZGETEX)
r�rrHrGr~rr:r��microsecondr5r�r�r-)r.r�r�r�r�r�r�Zopsetr0�s�msr1r1r2�getex�s>�









zBasicKeyCommands.getexcCs"|�|�}|dur|St|��dS)zg
        Return the value at key ``name``, raises a KeyError if the key
        doesn't exist.
        N)r.�KeyError�r.r�r�r1r1r2�__getitem__�s
zBasicKeyCommands.__getitem__)r�r�r+cCs|�d||�S)z�
        Returns an integer indicating the value of ``offset`` in ``name``

        For more information see https://redis.io/commands/getbit
        ZGETBITr,)r.r�r�r1r1r2�getbit�szBasicKeyCommands.getbit)rir[r\r+cCs|�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
        ZGETRANGEr,)r.rir[r\r1r1r2�getrangeszBasicKeyCommands.getrange�r�r�r+cCs|�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
        ZGETSETr,r�r1r1r2�getsets
zBasicKeyCommands.getsetcCs|�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
        rPr,rjr1r1r2rQszBasicKeyCommands.incrby��?cCs|�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
        ZINCRBYFLOATr,rjr1r1r2�incrbyfloat%szBasicKeyCommands.incrbyfloatr��r�r+cKs|jd|fi|��S)z~
        Returns a list of keys matching ``pattern``

        For more information see https://redis.io/commands/keys
        ZKEYSr,�r.r�r/r1r1r2rU.szBasicKeyCommands.keys�LEFT�RIGHT)�
first_list�second_list�srcrar+cCs||||g}|jdg|�R�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
        ZLMOVEr,)r.r�r�r�rar]r1r1r2�lmove6s
zBasicKeyCommands.lmove)r�r�r�r�rar+cCs |||||g}|jdg|�R�S)zo
        Blocking version of lmove.

        For more information see https://redis.io/commands/blmove
        ZBLMOVEr,)r.r�r�r�r�rar]r1r1r2�blmoveCs
zBasicKeyCommands.blmove�rUr5r+cGs>ddlm}t||�}i}|s&g||<|jdg|�Ri|��S)z�
        Returns a list of values ordered identically to ``keys``

        For more information see https://redis.io/commands/mget
        r)�EMPTY_RESPONSEZMGET)r�r�r'r-)r.rUr5r�r�r1r1r2�mgetSs
zBasicKeyCommands.mget)�mappingr+cCs.g}|��D]}|�|�q|jdg|�R�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
        ZMSET��itemsr�r-�r.r�r��pairr1r1r2�msetaszBasicKeyCommands.msetcCs.g}|��D]}|�|�q|jdg|�R�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
        ZMSETNXr�r�r1r1r2�msetnxns	zBasicKeyCommands.msetnx)r��dbr+cCs|�d||�S)z�
        Moves the key ``name`` to a different Redis database ``db``

        For more information see https://redis.io/commands/move
        ZMOVEr,)r.r�r�r1r1r2�move|szBasicKeyCommands.movecCs|�d|�S)zw
        Removes an expiration on ``name``

        For more information see https://redis.io/commands/persist
        r�r,rqr1r1r2r��szBasicKeyCommands.persistcCspt|tj�rt|��d�}t�}|r0|�d�|r>|�d�|rL|�d�|rZ|�d�|jd||g|�R�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
        r�ryrzr{r|ZPEXPIREr}r�r1r1r2�pexpire�s



zBasicKeyCommands.pexpirec	Cs�t|tj�r4t|jd�}tt�|����d|}t�}|rH|�d�|rV|�d�|rd|�d�|rr|�d�|j	d||g|�R�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
        r�ryrzr{r|Z	PEXPIREAT)
rGr~r:r�r5r�r�r�rHr-)	r.r�r�rurvrwrxr�r�r1r1r2�	pexpireat�s



zBasicKeyCommands.pexpireatcCs|�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
        ZPEXPIRETIMEr,r�r1r1r2�pexpiretime�szBasicKeyCommands.pexpiretime)r��time_msr�cCs,t|tj�rt|��d�}|�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
        r�ZPSETEX�rGr~rr:r�r-)r.r�r�r�r1r1r2�psetex�szBasicKeyCommands.psetexcCs|�d|�S)z�
        Returns the number of milliseconds until the key ``name`` will expire

        For more information see https://redis.io/commands/pttl
        ZPTTLr,rqr1r1r2�pttl�szBasicKeyCommands.pttl)rirE�
withvaluesr+cCs8g}|dur|�|�|r$|�d�|jd|g|�R�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
        NZ
WITHVALUESZ
HRANDFIELDrx)r.rirEr�r]r1r1r2�
hrandfield�s

zBasicKeyCommands.hrandfieldr?cKs|jdi|��S)zx
        Returns the name of a random key

        For more information see https://redis.io/commands/randomkey
        �	RANDOMKEY)r�r,rAr1r1r2�	randomkey	szBasicKeyCommands.randomkey�r��dstr+cCs|�d||�S)zr
        Rename key ``src`` to ``dst``

        For more information see https://redis.io/commands/rename
        ZRENAMEr,�r.r�r�r1r1r2�renameszBasicKeyCommands.rename)r�r�cCs|�d||�S)z�
        Rename key ``src`` to ``dst`` if ``dst`` doesn't already exist

        For more information see https://redis.io/commands/renamenx
        ZRENAMENXr,r�r1r1r2�renamenxszBasicKeyCommands.renamenx)r��ttlr�r�absttl�idletime�	frequencyr+c	Cs�|||g}|r|�d�|r&|�d�|durf|�d�z|�t|��Wntydtd��Yn0|dur�|�d�z|�t|��Wnty�td��Yn0|jdg|�R�S)	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
        rhZABSTTLNZIDLETIMEzidletimemust be an integerZFREQzfrequency must be an integerZRESTORE)rHr:r;rr-)	r.r�r�r�rr�r�r�r]r1r1r2�restore!s$




zBasicKeyCommands.restore)r�r�r�r�rurv�keepttlr.r�r�r+cCs�||g}i}|dur\|�d�t|tj�r>|�t|����nt|t�rT|�|�ntd��|dur�|�d�t|tj�r�|�t|��d��nt|t�r�|�|�ntd��|	dur�|�d�t|	tj�r�t|	jd�}
tt�	|	�
���|
}	|�|	�|
du�rP|�d	�t|
tj��rFt|
jd�}tt�	|
�
���d|}
|�|
�|�r`|�d
�|�rp|�d�|�r�|�d�|�r�|�d
�d|d<|jdg|�Ri|��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
        Nr�z$ex must be datetime.timedelta or intr�r�z$px must be datetime.timedelta or intr�r�r�ZKEEPTTLryrzrRTr.rT)rHrGr~rr:r�rr�r5r�r�r-)r.r�r�r�r�rurvr�r.r�r�r0r�r�r�r1r1r2rUSsL)












zBasicKeyCommands.set�r�r�cCs|�||�dSr<)rUr�r1r1r2�__setitem__�szBasicKeyCommands.__setitem__)r�r�r�r+cCs|rdp
d}|�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&rZSETBITr,�r.r�r�r�r1r1r2�setbit�szBasicKeyCommands.setbit)r�r5r�r+cCs(t|tj�rt|���}|�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
        ZSETEXr�)r.r�r5r�r1r1r2�setex�szBasicKeyCommands.setexcCs|�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
        ZSETNXr,r�r1r1r2�setnx�szBasicKeyCommands.setnxcCs|�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
        ZSETRANGEr,r�r1r1r2�setrange�s
zBasicKeyCommands.setrange�strings�LCSrU)	�algo�value1�value2�specific_argumentr��idx�minmatchlen�withmatchlenr+c	
Ks�dg}
||
vr&d�|
�}td|����|dvr6td��|rF|rFtd��||��||g}|rd|�d�|rr|�d�zt|�|�d	|g�Wnty�Yn0|r�|�d
�|jdg|�R||||d�|	��S)
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, zThe supported algorithms are: )rUr�z-specific_argument can be only keys or stringsz(len and idx cannot be provided together.sLENsIDXsMINMATCHLENsWITHMATCHLENZSTRALGO)r�r�r�r�)r�rrMrHr:r��	TypeErrorr-)
r.r�r�r�r�r�r�r�r�r/Zsupported_algoZsupported_algos_strr0r1r1r2�stralgo�s@ 



����zBasicKeyCommands.stralgocCs|�d|�S)z�
        Return the number of bytes stored in the value of ``name``

        For more information see https://redis.io/commands/strlen
        ZSTRLENr,rqr1r1r2�strlen	szBasicKeyCommands.strlen����r�r[r\r+cCs|�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.
        ZSUBSTRr,�r.r�r[r\r1r1r2�substr 	szBasicKeyCommands.substrr�cGs|jdg|�R�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
        ZTOUCHr,r�r1r1r2�touch'	szBasicKeyCommands.touchcCs|�d|�S)z�
        Returns the number of seconds until the key ``name`` will expire

        For more information see https://redis.io/commands/ttl
        ZTTLr,rqr1r1r2r�0	szBasicKeyCommands.ttlcCs|�d|�S)zs
        Returns the type of key ``name``

        For more information see https://redis.io/commands/type
        ZTYPEr,rqr1r1r2�type8	szBasicKeyCommands.typecGst�td��dS)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�DeprecationWarningrnr1r1r2�watch@	szBasicKeyCommands.watchcCst�td��dS)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~r1r1r2�unwatchH	szBasicKeyCommands.unwatchcGs|jdg|�R�S)z�
        Unlink one or more keys specified by ``names``

        For more information see https://redis.io/commands/unlink
        ZUNLINKr,rnr1r1r2�unlinkP	szBasicKeyCommands.unlinkr)�key1�key2r�r�r�r�r+cCsZ||g}|r|�d�|r$|�d�|dkr:|�d|g�|rH|�d�|jdg|�R�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
        ZLENZIDXrZMINMATCHLENZWITHMATCHLENr��rHr�r-)r.r�r�r�r�r�r�r0r1r1r2�lcsX	s


zBasicKeyCommands.lcs)NNN)N)NNN)NF)r&)FFFF)FFFF)NNNNF)r&)r�)r�)r�r�)r�r�)FFFF)FFFF)NF)FFNN)NNFFFFNN)r�FFNF)r�)FFrF)Rrprqrrrsr rrurHrr:rrtr^rBr_rbrervrrkZdecrrorrrsrt�__contains__rr�rr�r�r.r�r�r�r�r�r�rQ�incrr:r�r!rUr�r�rr�rrr�r�r�r�r�r�r�r�r�r�r�r�r�r�rUr�r�r�r�r�rr�r�r�r�r�r�r�r�r�r�r�r1r1r1r2rY�s�
�

��
�

�

�#�
�	
��)��%	�



�C
				����
��(��$		��
�

�6�



�U
�
�@	��rYcspeZdZed�dd�Zed�dd�Zed�dd�Zeed�d	d
�Zedd��fd
d�Z	dd��fdd�Z
�ZS)�AsyncBasicKeyCommandsrpcCstd��dS)Nz2Async Redis client does not support class deletion�r�rqr1r1r2rrw	sz!AsyncBasicKeyCommands.__delitem__cCstd��dS)Nz3Async Redis client does not support class inclusionr�rqr1r1r2r�z	sz"AsyncBasicKeyCommands.__contains__cCstd��dS)Nz3Async Redis client does not support class retrievalr�rqr1r1r2r�}	sz!AsyncBasicKeyCommands.__getitem__r�cCstd��dS)Nz4Async Redis client does not support class assignmentr�r�r1r1r2r��	sz!AsyncBasicKeyCommands.__setitem__Nrlc�st�j|�Sr<)r>r�rnr?r1r2r��	szAsyncBasicKeyCommands.watchr?c�s
t���Sr<)r>r�r~r?r1r2r��	szAsyncBasicKeyCommands.unwatch)rprqrrr rrr�r�rr�r�r�rAr1r1r?r2r�v	sr�c
@sHeZdZdZdEeeeeee	e	fd�dd�Z
dFeeeeee	e	fd�dd�ZdGeeeeeeeeeefd�d	d
�Z
dd�eeeeeeeee	d
�dd�Zddd�eeeeeeeee	e	fd�dd�Zeeeeeeeefd�dd�Zeeeeeeeefd�dd�Zeeeeefd�dd�ZdHeeeeeedfd�dd �Zeeeeeefd!�d"d#�Zeeeeeefd!�d$d%�Zeeeeee	e	fd&�d'd(�Zeeeeeeefd)�d*d+�Zeeeeeeefd,�d-d.�Zeeeeeeefd&�d/d0�ZdIeeeeeedfd�d1d2�Zeeeeeefd3�d4d5�Zeeeeeefd!�d6d7�Zeeeeeefd8�d9d:�ZdJeeeeeeeeeeedfd;�d<d=�Z dKeeeeeeeeeee!e!eeee!eeefd?�
d@dA�Z"dLeeeeeeeeeee!e!e	dB�dCdD�Z#dS)M�ListCommandsz^
    Redis commands for List data type.
    see: https://redis.io/topics/data-types#lists
    r�rUr�r+cCs2|durd}t|d�}|�|�|jdg|�R�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
        NrZBLPOP�r'rHr-�r.rUr�r1r1r2�blpop�	s


zListCommands.blpopcCs2|durd}t|d�}|�|�|jdg|�R�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
        NrZBRPOPr�r�r1r1r2�brpop�	s


zListCommands.brpop)r�r�r�r+cCs|durd}|�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
        NrZ
BRPOPLPUSHr,)r.r�r�r�r1r1r2�
brpoplpush�	s
zListCommands.brpoplpushr&)rE)r��numkeysr5�	directionrEr+cGs*||g|�|�d�|�}|jdg|�R�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
        �COUNTZBLMPOPr,)r.r�r�rrEr5r1r1r2�blmpop�	szListCommands.blmpopN)rrE)�num_keysr5rrEr+cGs<|gt|�|g}|dkr*|�d|g�|jdg|�R�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&rZLMPOP)r�r�r-)r.rrrEr5r1r1r2�lmpop�	s
zListCommands.lmpop)r�r�r+cCs|�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
        ZLINDEXr,)r.r�r�r1r1r2�lindex�	szListCommands.lindex)r��where�refvaluer�r+cCs|�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
        ZLINSERTr,)r.r�rrr�r1r1r2�linsert
szListCommands.linsertr�cCs|�d|�S)zy
        Return the length of the list ``name``

        For more information see https://redis.io/commands/llen
        ZLLENr,rqr1r1r2�llen
szListCommands.llen�r�rEr+cCs&|dur|�d||�S|�d|�SdS)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
        NZLPOPr,�r.r�rEr1r1r2�lpop
s
zListCommands.lpop�r��valuesr+cGs|jd|g|�R�S)z�
        Push ``values`` onto the head of the list ``name``

        For more information see https://redis.io/commands/lpush
        ZLPUSHr,�r.r�rr1r1r2�lpush%
szListCommands.lpushcGs|jd|g|�R�S)z�
        Push ``value`` onto the head of the list ``name`` if ``name`` exists

        For more information see https://redis.io/commands/lpushx
        ZLPUSHXr,rr1r1r2�lpushx-
szListCommands.lpushxr�cCs|�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
        ZLRANGEr,r�r1r1r2�lrange5
s
zListCommands.lrange)r�rEr�r+cCs|�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
        ZLREMr,)r.r�rEr�r1r1r2�lremA
szListCommands.lrem)r�r�r�r+cCs|�d|||�S)z�
        Set element at ``index`` of list ``name`` to ``value``

        For more information see https://redis.io/commands/lset
        ZLSETr,)r.r�r�r�r1r1r2�lsetO
szListCommands.lsetcCs|�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
        ZLTRIMr,r�r1r1r2�ltrimW
s
zListCommands.ltrimcCs&|dur|�d||�S|�d|�SdS)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
        NZRPOPr,rr1r1r2�rpopc
s
zListCommands.rpopr�cCs|�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
        Z	RPOPLPUSHr,r�r1r1r2�	rpoplpushr
szListCommands.rpoplpushcGs|jd|g|�R�S)z�
        Push ``values`` onto the tail of the list ``name``

        For more information see https://redis.io/commands/rpush
        ZRPUSHr,rr1r1r2�rpush{
szListCommands.rpushr�cCs|�d||�S)z�
        Push ``value`` onto the tail of the list ``name`` if ``name`` exists

        For more information see https://redis.io/commands/rpushx
        ZRPUSHXr,r�r1r1r2�rpushx�
szListCommands.rpushx)r�r��rankrE�maxlenr+cCs\||g}|dur|�d|g�|dur4|�d|g�|durJ|�d|g�|jdg|�R�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
        NZRANKrZMAXLENZLPOS�r�r-)r.r�r�rrErr0r1r1r2�lpos�
s!zListCommands.lposF)
r�r[r,�byr.�desc�alpha�store�groupsr+c

Cs,|dur|dus |dur(|dur(td��|g}
|durD|
�d|g�|durd|durd|
�d||g�|dur�t|ttf�r�|
�d|g�n|D]}|
�d|g�q�|r�|
�d�|r�|
�d�|dur�|
�d|g�|	r�|r�t|ttf�s�t|�d	kr�td
��d|	�rt|�ndi}|jdg|
�Ri|��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 specifiedsBY�LIMITsGET�DESCsALPHA�STOREr�zVwhen using "groups" the "get" argument must be specified and contain at least two keysr"ZSORT)rr�rG�bytesrtrHr�r-)
r.r�r[r,rr.rr r!r"r0�gr�r1r1r2�sort�
s2% 

�zListCommands.sort)rir[r,rr.rr r+c	Cs|j|||||||d�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,rr.rr )r))r.rir[r,rr.rr r1r1r2�sort_ros�zListCommands.sort_ro)r)r)r)N)N)NNN)NNNNFFNF)NNNNFF)$rprqrrrsr
rr:rrr�r�r�rtr�r:rrrrr	rrrrrrrrrrrrrrvr)r*r1r1r1r2r��	s������
�������"    "	��0�

�K�
�r�c@szeZdZdZdeeedfeedfeedfed�dd�Z	deedfeedfeedfe
d�dd	�Zdeeeedfeedfed
�dd�Z
deeedfeedfe
d
�dd�Zdeeeedfeedfed
�dd�Zdeeedfeedfe
d
�dd�Zdddefeeeedfeedfeeefed�dd�Zddefeeedfeedfeeefe
d�dd�ZdS) �ScanCommandszF
    Redis SCAN commands.
    see: https://redis.io/commands/scan
    rN)�cursor�matchrEr�r+cKs`|g}|dur|�d|g�|dur2|�d|g�|durH|�d|g�|jdg|�Ri|��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
        N�MATCH�COUNTr�ZSCANr)r.r,r-rEr�r/r0r1r1r2�scan+szScanCommands.scan�r-rEr�r+cks:d}|dkr6|jf||||d�|��\}}|EdHqdS�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)r,r-rEr�N�r0)r.r-rEr�r/r,�datar1r1r2�	scan_iterLs��
zScanCommands.scan_iter)r�r,r-rEr+cCsF||g}|dur|�d|g�|dur4|�d|g�|jdg|�R�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
        Nr.r/ZSSCANr�r.r�r,r-rEr0r1r1r2�sscanhszScanCommands.sscan�r�r-rEr+ccs2d}|dkr.|j||||d�\}}|EdHqdS�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
        r3r�r,r-rEN�r8�r.r�r-rEr,r5r1r1r2�
sscan_iter�szScanCommands.sscan_itercCsF||g}|dur|�d|g�|dur4|�d|g�|jdg|�R�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
        Nr.r/ZHSCANrr7r1r1r2�hscan�szScanCommands.hscanccs6d}|dkr2|j||||d�\}}|��EdHqdS�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
        r3rr;N�r?r�r=r1r1r2�
hscan_iter�szScanCommands.hscan_iter)r�r,r-rE�score_cast_funcr+cCsT||g}|dur|�d|g�|dur4|�d|g�d|i}|jdg|�Ri|��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
        Nr.r/rCZZSCANr)r.r�r,r-rErCr0r�r1r1r2�zscan�szScanCommands.zscan�r�r-rErCr+ccs4d}|dkr0|j|||||d�\}}|EdHqdS�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
        r3r)r,r-rErCN�rD)r.r�r-rErCr,r5r1r1r2�
zscan_iter�s�
zScanCommands.zscan_iter)rNNN)NNN)rNN)NN)rNN)NN)rprqrrrsr:rr!rtrur0r	r6r r8r>r?rBr:r�rrDrHr1r1r1r2r+%s��


�#�


��

��

��

��

��


��


�r+c@s�eZdZd
eedfeedfeedfed�dd�Zde	eedfeedfed�dd�Z
deeedfeedfed�dd	�Zddefe	eedfeedfee
efed
�dd�ZdS)�AsyncScanCommandsNr1cKsFd}|dkrB|jf||||d�|��IdH\}}|D]
}|Vq4qdSr2r4)r.r-rEr�r/r,r5�dr1r1r2r6�s��zAsyncScanCommands.scan_iterr9cCs>d}|dkr:|j||||d�IdH\}}|D]
}|Vq,qdSr:r<)r.r�r-rEr,r5rJr1r1r2r>s�zAsyncScanCommands.sscan_itercCsBd}|dkr>|j||||d�IdH\}}|��D]
}|Vq0qdSr@rA)r.r�r-rEr,r5�itr1r1r2rB+s�zAsyncScanCommands.hscan_iterrEcCs@d}|dkr<|j|||||d�IdH\}}|D]
}|Vq.qdSrFrG)r.r�r-rErCr,r5rJr1r1r2rHAs�zAsyncScanCommands.zscan_iter)NNN)NN)NN)rprqrrrr!r:rtrr6r r>rBr:r�rrHr1r1r1r2rI�sF�


� �

��

��


�rIc@seZdZdZeeeeeefd�dd�Z	eeeeefd�dd�Z
eeeeeefd�d	d
�Z
eeeeeeefd�dd
�Zeeeeeefd�dd�Zd.eeeeeeeefd�dd�Zeeeeeeefd�dd�Zeeeeeefd�dd�Zeeeeefd�dd�Zeeeeeeeeefd�dd�Zeeeeeeefd�dd �Zd/eeeeeed!fd"�d#d$�Zd0eeeeeed!fd%�d&d'�Zeeeeeefd�d(d)�Zeeeeeefd�d*d+�Zeeeeeeefd�d,d-�Zd!S)1�SetCommandsz\
    Redis commands for Set data type.
    see: https://redis.io/topics/data-types#sets
    r
cGs|jd|g|�R�S)zs
        Add ``value(s)`` to set ``name``

        For more information see https://redis.io/commands/sadd
        ZSADDr,rr1r1r2�saddeszSetCommands.saddr�cCs|�d|�S)z�
        Return the number of elements in set ``name``

        For more information see https://redis.io/commands/scard
        ZSCARDr,rqr1r1r2�scardmszSetCommands.scardr�cGst||�}|jdg|�R�S)z�
        Return the difference of sets specified by ``keys``

        For more information see https://redis.io/commands/sdiff
        ZSDIFF�r'r-�r.rUr5r1r1r2�sdiffus
zSetCommands.sdiff)rarUr5r+cGst||�}|jd|g|�R�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
        Z
SDIFFSTORErO�r.rarUr5r1r1r2�
sdiffstore~s	
zSetCommands.sdiffstorecGst||�}|jdg|�R�S)z�
        Return the intersection of sets specified by ``keys``

        For more information see https://redis.io/commands/sinter
        ZSINTERrOrPr1r1r2�sinter�s
zSetCommands.sinterr�r�rU�limitr+cCs$|g|�d�|�}|jdg|�R�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
        �LIMITZ
SINTERCARDr,�r.r�rUrVr5r1r1r2�
sintercard�szSetCommands.sintercardcGst||�}|jd|g|�R�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
        ZSINTERSTORErOrRr1r1r2�sinterstore�s	
zSetCommands.sinterstorer�cCs|�d||�S)z�
        Return a boolean indicating if ``value`` is a member of set ``name``

        For more information see https://redis.io/commands/sismember
        Z	SISMEMBERr,r�r1r1r2�	sismember�szSetCommands.sismembercCs|�d|�S)z}
        Return all members of the set ``name``

        For more information see https://redis.io/commands/smembers
        ZSMEMBERSr,rqr1r1r2�smembers�szSetCommands.smembers)r�rr5r+cGst||�}|jd|g|�R�S)z�
        Return whether each value in ``values`` is a member of the set ``name``
        as a list of ``bool`` in the order of ``values``

        For more information see https://redis.io/commands/smismember
        Z
SMISMEMBERrO)r.r�rr5r1r1r2�
smismember�s	
zSetCommands.smismember)r�r�r�r+cCs|�d|||�S)z�
        Move ``value`` from set ``src`` to set ``dst`` atomically

        For more information see https://redis.io/commands/smove
        ZSMOVEr,)r.r�r�r�r1r1r2�smove�szSetCommands.smoveNr
cCs&|dur|gpg}|jd|g|�R�S)z�
        Remove and return a random member of set ``name``

        For more information see https://redis.io/commands/spop
        NZSPOPr,)r.r�rEr5r1r1r2�spop�szSetCommands.spop)r��numberr+cCs&|dur|gpg}|jd|g|�R�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
        NZSRANDMEMBERr,)r.r�r`r5r1r1r2�srandmember�szSetCommands.srandmembercGs|jd|g|�R�S)zv
        Remove ``values`` from set ``name``

        For more information see https://redis.io/commands/srem
        ZSREMr,rr1r1r2�srem�szSetCommands.sremcGst||�}|jdg|�R�S)z�
        Return the union of sets specified by ``keys``

        For more information see https://redis.io/commands/sunion
        ZSUNIONrOrPr1r1r2�sunion�s
zSetCommands.sunioncGst||�}|jd|g|�R�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
        ZSUNIONSTORErOrRr1r1r2�sunionstore�s	
zSetCommands.sunionstore)r)N)N)rprqrrrsrtrrrr:rMrNr
r�rQrSrTrYrZrvr[r\r]r^rr_rarbrcrdr1r1r1r2rL_sB
�
�
��	� "
��
�rLc
@s�eZdZdZeeeed�dd�ZdEee	e
efeee
dfeeeedfee
dfed	�	d
d�ZdFeeee
e
ee
dfeed
�dd�ZdGeeee
eeeegee
dfee
dfee
dfeeed�dd�Zeeed�dd�ZdHeeeeee
ed�dd�Zeeeed�dd�Zeeed�dd�Zeeeed�d d!�ZdIeeeee
ed"�d#d$�Zeeed�d%d&�Zeed'�d(d)�ZdJeeed*�d+d,�Zeed'�d-d.�Zeeed�d/d0�Z dKeeeee
eedfee
dfed1�d2d3�Z!dLeeeee
dfed6�d7d8�Z"dMe	eefee
dfee
dfed9�d:d;�Z#dNe$e$e	eefee
dfee
dfeed<�d=d>�Z%dOeeeee
dfed?�d@dA�Z&dPeee
dfeeedfee
dfedB�dCdD�Z'dS)Q�StreamCommandsz]
    Redis commands for Stream data type.
    see: https://redis.io/topics/streams-intro
    )r��	groupname�idsr+cGs|jd||g|�R�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
        ZXACKr,)r.r�rfrgr1r1r2�xack
s	zStreamCommands.xackr�NTF)	r��fields�idr�approximate�
nomkstream�minidrVr+c	Csg}	|dur|durtd��|durdt|t�r6|dkr>td��|	�d�|rV|	�d�|	�t|��|dur�|	�d�|r�|	�d�|	�|�|dur�|	�d|g�|r�|	�d	�|	�|�t|t�r�t|�d
kr�td��|��D]}
|	�|
�q�|j	d|g|	�R�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
        Nz8Only one of ```maxlen``` or ```minid``` may be specifiedr&z&XADD maxlen must be a positive integer�MAXLENr_�MINIDr$s
NOMKSTREAMrz$XADD fields must be a non-empty dictZXADD)
rrGr:rHrtr��dictr�r�r-)r.r�rirjrrkrlrmrVr0r�r1r1r2�xadd
s6�






zStreamCommands.xaddr)r�rf�consumername�
min_idle_time�start_idrE�justidr+c
Cs�zt|�dkrtd��Wnty*Yn0i}|||||g}	z&t|�dkrTtd��|	�d|g�WntyvYn0|r�|	�d�d|d<|jdg|	�Ri|��S)	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
        rz6XAUTOCLAIM min_idle_time must be a nonnegative integer�%XPENDING count must be a integer >= 0r/�JUSTIDT�parse_justidZ
XAUTOCLAIM)r:rr�r�rHr-)
r.r�rfrrrsrtrErur/r0r1r1r2�
xautoclaimS
s&�
zStreamCommands.xautoclaim)r�rfrrrs�message_ids�idler5�
retrycountr]rur+c
Cs>t|t�r|dkrtd��t|ttf�r,|s4td��i}|||t|�g}|�t|��|dur�t|t�sptd��|�dt|�f�|dur�t|t�s�td��|�dt|�f�|dur�t|t�s�td	��|�d
t|�f�|	r�t|	t�s�td��|�d�|
�r&t|
t��std
��|�d�d|d<|j	dg|�Ri|��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
        rz3XCLAIM min_idle_time must be a non negative integerzLXCLAIM message_ids must be a non empty list or tuple of message IDs to claimNzXCLAIM idle must be an integersIDLEzXCLAIM time must be an integersTIMEz$XCLAIM retrycount must be an integers
RETRYCOUNTzXCLAIM force must be a booleansFORCEzXCLAIM justid must be a booleanrwTrxZXCLAIM)
rGr:rr��tuplertr�rvrHr-)
r.r�rfrrrsrzr{r5r|r]rur/r0r1r1r2�xclaim�
s>%�





zStreamCommands.xclaim)r�rgr+cGs|jd|g|�R�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
        ZXDELr,)r.r�rgr1r1r2�xdel�
szStreamCommands.xdel�$)r�rfrj�mkstream�entries_readr+cCs:d|||g}|r|�d�|dur0|�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 CREATEsMKSTREAMN�ENTRIESREADr�)r.r�rfrjr�r�r0r1r1r2�
xgroup_create�
s
zStreamCommands.xgroup_create)r�rfrrr+cCs|�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
        zXGROUP DELCONSUMERr,�r.r�rfrrr1r1r2�xgroup_delconsumer�
s
z!StreamCommands.xgroup_delconsumer)r�rfr+cCs|�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
        zXGROUP DESTROYr,�r.r�rfr1r1r2�xgroup_destroyszStreamCommands.xgroup_destroycCs|�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
        zXGROUP CREATECONSUMERr,r�r1r1r2�xgroup_createconsumer
s
�z$StreamCommands.xgroup_createconsumer)r�rfrjr�r+cCs2|||g}|dur |�d|g�|jdg|�R�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
        Nr�zXGROUP SETIDr)r.r�rfrjr�r0r1r1r2�xgroup_setids
zStreamCommands.xgroup_setidcCs|�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
        zXINFO CONSUMERSr,r�r1r1r2�xinfo_consumers/szStreamCommands.xinfo_consumersr�cCs|�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 GROUPSr,rqr1r1r2�xinfo_groups9szStreamCommands.xinfo_groups)r��fullr+cCs8|g}i}|r |�d�d|i}|jdg|�Ri|��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
        sFULLr�zXINFO STREAMrx)r.r�r�r0r�r1r1r2�xinfo_streamBs
zStreamCommands.xinfo_streamcCs|�d|�S)z�
        Returns the number of elements in a given stream.

        For more information see https://redis.io/commands/xlen
        ZXLENr,rqr1r1r2�xlenQszStreamCommands.xlencCs|�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
        �XPENDINGr,r�r1r1r2�xpendingYszStreamCommands.xpending)r�rf�min�maxrErrr{r+c	Cs�|||hdhkr4|dus |dur(td��|�||�S||g}|dusT|dusT|dur\td��z&t|�dkrrtd��|�d|g�Wnty�Yn0z(t|�dkr�td��|�|||g�Wnty�Yn0|r�|�|�|jdg|�Rd	d
i�S)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.rz$XPENDING idle must be a integer >= 0ZIDLErvr�Zparse_detailT)rr�r:r�r�rHr-)	r.r�rfr�r�rErrr{r0r1r1r2�xpending_rangecs4��
zStreamCommands.xpending_range�-�+)r�r�r�rEr+cCsV||g}|durBt|t�r"|dkr*td��|�d�|�t|��|jd|g|�R�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
        Nr&z'XRANGE count must be a positive integerr/ZXRANGE�rGr:rrHrtr-)r.r�r�r�rEr0r1r1r2�xrange�s
zStreamCommands.xrange)�streamsrE�blockr+cCs�g}|dur>t|t�r|dkr&td��|�d�|�t|��|durxt|t�rX|dkr`td��|�d�|�t|��t|t�r�t|�dkr�td��|�d	�t|���\}}|�	|�|�	|�|j
d
g|�R�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
        Nrz*XREAD block must be a non-negative integer�BLOCKr&z&XREAD count must be a positive integerr/z&XREAD streams must be a non empty dict�STREAMSZXREAD)rGr:rrHrtrpr��zipr�r�r-)r.r�rEr�r0rUrr1r1r2�xread�s$




zStreamCommands.xread)rfrrr�rEr��noackr+cCs�d||g}|durDt|t�r$|dkr,td��|�d�|�t|��|dur~t|t�r^|dkrftd��|�d�|�t|��|r�|�d	�t|t�r�t|�dkr�td
��|�d�|�|���|�|�	��|j
dg|�R�S)
a=
        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
        sGROUPNr&z+XREADGROUP count must be a positive integerr/rz/XREADGROUP block must be a non-negative integerr�sNOACKz+XREADGROUP streams must be a non empty dictr�Z
XREADGROUP)rGr:rrHrtrpr�r�rUrr-)r.rfrrr�rEr�r�r0r1r1r2�
xreadgroup�s&




zStreamCommands.xreadgroup)r�r�r�rEr+cCsV||g}|durBt|t�r"|dkr*td��|�d�|�t|��|jd|g|�R�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
        Nr&z*XREVRANGE count must be a positive integerr/Z	XREVRANGEr�)r.r�r�r�rEr0r1r1r2�	xrevranges
zStreamCommands.xrevrange)r�rrkrmrVr+cCs�g}|dur|durtd��|dur4|dur4td��|durF|�d�|durX|�d�|rf|�d�|durx|�|�|dur�|�|�|dur�|�d�|�|�|jd|g|�R�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
        Nz4Only one of ``maxlen`` or ``minid`` may be specifiedz0One of ``maxlen`` or ``minid`` must be specifiedrnror_r$ZXTRIMrd)r.r�rrkrmrVr0r1r1r2�xtrim!s&






zStreamCommands.xtrim)r�NTFNN)rNF)NNNFF)r�FN)N)F)NN)r�r�N)NN)NNF)r�r�N)NTNN)(rprqrrrsr rr#rurhrrrrr:rvrqrryr
rr~rrr�r�r�r�r�r�r�r�r�r�r�r�r�rtr�r�r�r1r1r1r2re
s$�



�=�
�:�


�I������
	�

�<�
��


�(�


�-�
��


�rec@s�eZdZdZdheeeefeeeeeee	d�	dd�Z
ee	d�dd�Zeeee	d	�d
d�Z
dieee	d�d
d�Zeee	d�dd�Zeeee	d�dd�Zdjeeedfee	d�dd�Zdkeeeeeeeffeedfe	d�dd�Zdleeeeeeeefd�dd�Zd d!�Zdmeeedfe	d"�d#d$�Zdneeedfe	d"�d%d&�Zdoeeee	d'�d(d)�Zdpee e	d*�d+d,�Z!dqee e	d*�d-d.�Z"dreeee#ee#ee#eeee$e$fd0�d1d2�Z%dseeeee#ee#ee#ee#e$d3�d4d5�Z&ddddeddfeedfeeeeeeeee'e(dfeedfeedfe	d6�d7d8�Z)ddeddddfeeeeeee'e(feeeee	d9�d:d;�Z*defeeeeee'e(fe	d<�d=d>�Z+dteeeeeeeeedfeedfe	d?�
d@dA�Z,dueeeeedfeedfe	dB�dCdD�Z-dveeeeedfeedfe	dE�dFdG�Z.dddefeeeeedfeedfeee'e(fe	dH�dIdJ�Z/dddefeeeeedfeedfeee'e(fdK�dLdM�Z0eee	dN�dOdP�Z1ee2e	dQ�dRdS�Z3eeee	d	�dTdU�Z4eeee	d	�dVdW�Z5eeee	d	�dXdY�Z6eee	dN�dZd[�Z7eee	dN�d\d]�Z8dweeeeeeffeedfee	d�d^d_�Z9dxeeeeeeeffeedfe	d�d`da�Z:eeee	db�dcdd�Z;dyeeedfeeeeeeffeedfe	de�dfdg�Z<dS)z�SortedSetCommandszw
    Redis commands for Sorted Sets data type.
    see: https://redis.io/topics/data-types-intro#redis-sorted-sets
    F)	r�r�rurv�chr�rwrxr+c	Cs|std��|r|rtd��|r,|r,td��|rDt|�dkrDtd��|rX|sP|rXtd��g}	i}
|rn|	�d�|r||	�d�|r�|	�d	�|r�|	�d
�d|
d<|r�|	�d
�|r�|	�d�|��D] }|	�|d�|	�|d�q�|jd|g|	�Ri|
��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.sNXsXXsCHsINCRTZas_scoresGTsLTrZZADD)rr�rHr�r-)r.r�r�rurvr�r�rwrxr0r�r�r1r1r2�zaddVs>,�





zSortedSetCommands.zaddr�cCs|�d|�S)z�
        Return the number of elements in the sorted set ``name``

        For more information see https://redis.io/commands/zcard
        ZZCARDr,rqr1r1r2�zcard�szSortedSetCommands.zcard)r�r�r�r+cCs|�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
        ZZCOUNTr,�r.r�r�r�r1r1r2�zcount�szSortedSetCommands.zcount)rU�
withscoresr+cCs.t|�g|�}|r|�d�|jdg|�R�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
        �
WITHSCORESZZDIFF)r�rHr-)r.rUr�r0r1r1r2�zdiff�s
zSortedSetCommands.zdiff)rarUr+cCs"t|�g|�}|jd|g|�R�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
        Z
ZDIFFSTORE)r�r-)r.rarUr0r1r1r2�
zdiffstore�szSortedSetCommands.zdiffstore)r�rir�r+cCs|�d|||�S)z�
        Increment the score of ``value`` in sorted set ``name`` by ``amount``

        For more information see https://redis.io/commands/zincrby
        ZZINCRBYr,)r.r�rir�r1r1r2�zincrby�szSortedSetCommands.zincrbyN)rU�	aggregater�r+cCs|jdd|||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
        ZZINTERN�r���_zaggregate�r.rUr�r�r1r1r2�zinter�szSortedSetCommands.zinter)rarUr�r+cCs|�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
        ZZINTERSTOREr��r.rarUr�r1r1r2�zinterstore�szSortedSetCommands.zinterstorerrUcCs$|g|�d�|�}|jdg|�R�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
        rWZ
ZINTERCARDr,rXr1r1r2�
zintercard�szSortedSetCommands.zintercardcCs|�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
        Z	ZLEXCOUNTr,r�r1r1r2�	zlexcountszSortedSetCommands.zlexcountr
cCs4|dur|gpg}ddi}|jd|g|�Ri|��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
        Nr�TZZPOPMAXr,�r.r�rEr5r�r1r1r2�zpopmaxszSortedSetCommands.zpopmaxcCs4|dur|gpg}ddi}|jd|g|�Ri|��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
        Nr�TZZPOPMINr,r�r1r1r2�zpopminszSortedSetCommands.zpopmin)rirEr�r+cCs8g}|dur|�|�|r$|�d�|jd|g|�R�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
        Nr�ZZRANDMEMBERrx)r.rirEr�r]r1r1r2�zrandmember$s

zSortedSetCommands.zrandmemberr�cCs2|durd}t|d�}|�|�|jdg|�R�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
        NrZBZPOPMAXr�r�r1r1r2�bzpopmax>s



zSortedSetCommands.bzpopmaxcCs2|durd}t|d�}|�|�|jdg|�R�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
        NrZBZPOPMINr�r�r1r1r2�bzpopminQs



zSortedSetCommands.bzpopminr&)rrUr�r�rEr+cCsb|g|}|r|s|s |s t�n|r0|�d�n
|�d�|dkrP|�d|g�|jdg|�R�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&rZZMPOP�rrHr�r-)r.rrUr�r�rEr5r1r1r2�zmpopds

zSortedSetCommands.zmpop)r�r�rUr�r�rEr+cCs`||g|�}|r|s|s&|s&td��n|r6|�d�n
|�d�|�d|g�|jdg|�R�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�rZBZMPOPr�)r.r�r�rUr�r�rEr5r1r1r2�bzmpop}s

zSortedSetCommands.bzmpop)rar�r[r\r�byscore�bylexr�rCr�r,r+c
Cs�|r|rtd��|dur |dus0|dur8|dur8td��|rH|	rHtd��|g}
|r\|
�|�|
�|||g�|rz|
�d�|r�|
�d�|r�|
�d�|dur�|dur�|
�d||g�|	r�|
�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``.ZBYSCOREZBYLEXZREVrWr��r�rCr�)r.r�rar�r[r\rr�r�r�rCr�r,r0r�r1r1r2�_zrange�s4� �





zSortedSetCommands._zrange)r�r[r\rr�rCr�r�r�r,r+cCsN|s.|s.|	dur.|
dur.|r.|�|||||�S|�dd|||||||||	|
�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
        NZZRANGE)�	zrevranger�)r.r�r[r\rr�rCr�r�r�r,r1r1r2�zrange�s +�zSortedSetCommands.zrange)r�r[r\r�rCr+cCs4d|||g}|r|�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
        Z	ZREVRANGE�
WITHSCORESr�rx)r.r�r[r\r�rCr0r�r1r1r2r�s


zSortedSetCommands.zrevrange)
rar�r[r\r�r�rr�r,r+c

Cs |�d|||||||dd||	�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
        ZZRANGESTOREFN)r�)
r.rar�r[r\r�r�rr�r,r1r1r2�zrangestores#�zSortedSetCommands.zrangestore)r�r�r�r[r,r+cCs^|dur|dus |dur(|dur(td��d|||g}|durT|durT|�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
        Nr#ZZRANGEBYLEXr$�rr�r-)r.r�r�r�r[r,r0r1r1r2�zrangebylexQs zSortedSetCommands.zrangebylex)r�r�r�r[r,r+cCs^|dur|dus |dur(|dur(td��d|||g}|durT|durT|�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
        Nr#ZZREVRANGEBYLEXrWr�)r.r�r�r�r[r,r0r1r1r2�zrevrangebylexis z SortedSetCommands.zrevrangebylex)r�r�r�r[r,r�rCr+c
Cs||dur|dus |dur(|dur(td��d|||g}|durT|durT|�d||g�|rb|�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
        Nr#Z
ZRANGEBYSCORErWr�r��rr�rHr-)
r.r�r�r�r[r,r�rCr0r�r1r1r2�
zrangebyscore�s 

zSortedSetCommands.zrangebyscore)r�r�r�r[r,r�rCc
Cs||dur|dus |dur(|dur(td��d|||g}|durT|durT|�d||g�|rb|�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
        Nr#ZZREVRANGEBYSCORErWr�r�r�)
r.r�r�r�r[r,r�rCr0r�r1r1r2�zrevrangebyscore�s 

z"SortedSetCommands.zrevrangebyscorer�cCs|�d||�S)z�
        Returns a 0-based value indicating the rank of ``value`` in sorted set
        ``name``

        For more information see https://redis.io/commands/zrank
        ZZRANKr,r�r1r1r2�zrank�szSortedSetCommands.zrankr
cGs|jd|g|�R�S)z�
        Remove member ``values`` from sorted set ``name``

        For more information see https://redis.io/commands/zrem
        ZZREMr,rr1r1r2�zrem�szSortedSetCommands.zremcCs|�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
        ZZREMRANGEBYLEXr,r�r1r1r2�zremrangebylex�s	z SortedSetCommands.zremrangebylexcCs|�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
        ZZREMRANGEBYRANKr,r�r1r1r2�zremrangebyrank�s	z!SortedSetCommands.zremrangebyrankcCs|�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
        ZZREMRANGEBYSCOREr,r�r1r1r2�zremrangebyscore�s	z"SortedSetCommands.zremrangebyscorecCs|�d||�S)z�
        Returns a 0-based value indicating the descending rank of
        ``value`` in sorted set ``name``

        For more information see https://redis.io/commands/zrevrank
        ZZREVRANKr,r�r1r1r2�zrevrank�szSortedSetCommands.zrevrankcCs|�d||�S)z�
        Return the score of element ``value`` in sorted set ``name``

        For more information see https://redis.io/commands/zscore
        ZZSCOREr,r�r1r1r2�zscoreszSortedSetCommands.zscorecCs|jdd|||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
        ZZUNIONNr�r�r�r1r1r2�zunionszSortedSetCommands.zunioncCs|�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
        ZZUNIONSTOREr�r�r1r1r2�zunionstores
zSortedSetCommands.zunionstore)ri�membersr+cCs(|std��|g|}|jdg|�R�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 listZZMSCOREr�)r.rir�r0r1r1r2�zmscore's
zSortedSetCommands.zmscore)r�rarUr�r+cKs�|g}|dur|�|�|�t|��t|t�rD|��|��}}nd}|�|�|rj|�d�|�|�|r�|��dvr�|�d�|�|�ntd��|�	dd�r�|�d�|j
|i|��S)NsWEIGHTS)ZSUMr�r�s	AGGREGATEz!aggregate can be sum, min or max.r�Fr�)rHr�rGrprUrr�rMrr.r-)r.r�rarUr�r�r0Zweightsr1r1r2r�7s&






zSortedSetCommands._zaggregate)FFFFFF)F)NF)N)r)N)N)NF)r)r)FFr&)FFr&)FFFNN)NN)NN)NF)N)N)=rprqrrrsr rrrrvrur�r�r%r�rr�r�r:r�rrtr�r
r�r:r
rr�r�r�r�r�r$r�r�rr�r�r�r�rr�r�r�r�r�r�r�r�r�rr�r�r�r�r�r�r�r�r�r�r1r1r1r2r�Ps�	�
�N	
	���
��
�	������'�


�/�
�B�
�!�

�7�

��

��


�'�


�"	�	�
��
��

�r�c@sDeZdZdZeeed�dd�Zeed�dd�Zeeed�d	d
�Z	dS)�HyperlogCommandszr
    Redis commands of HyperLogLogs data type.
    see: https://redis.io/topics/data-types-intro#hyperloglogs
    r
cGs|jd|g|�R�S)z�
        Adds the specified elements to the specified HyperLogLog.

        For more information see https://redis.io/commands/pfadd
        ZPFADDr,rr1r1r2�pfadd_szHyperlogCommands.pfadd)�sourcesr+cGs|jdg|�R�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
        ZPFCOUNTr,)r.r�r1r1r2�pfcountgszHyperlogCommands.pfcount)rar�r+cGs|jd|g|�R�S)z�
        Merge N different HyperLogLogs into a single one.

        For more information see https://redis.io/commands/pfmerge
        ZPFMERGEr,)r.rar�r1r1r2�pfmergepszHyperlogCommands.pfmergeN)
rprqrrrsr rrur�r�r�r1r1r1r2r�Ys	r�c	@s�eZdZdZeeeeeefd�dd�Z	eeeee
e
fd�dd�Zeeeeeeeefd�dd	�Z
eeeeefd
�dd�Zd)eeeeeeefd�dd�Zd*eeeeeeefd�dd�Zeeeeefd
�dd�Zeeeeefd
�dd�Zd+eeeeeeeeeeeeefd�dd�Zeeeeee
e
fd�dd�Zeeeeeefd�d d!�Zeeeeeeefd"�d#d$�Zeeeeefd
�d%d&�Zeeeeeefd�d'd(�ZdS),�HashCommandszk
    Redis commands for Hash data type.
    see: https://redis.io/topics/data-types-intro#redis-hashes
    )r�rUr+cGs|jd|g|�R�S)zu
        Delete ``keys`` from hash ``name``

        For more information see https://redis.io/commands/hdel
        ZHDELr,)r.r�rUr1r1r2�hdel�szHashCommands.hdel)r�rir+cCs|�d||�S)z�
        Returns a boolean indicating if ``key`` exists within hash ``name``

        For more information see https://redis.io/commands/hexists
        ZHEXISTSr,�r.r�rir1r1r2�hexists�szHashCommands.hexistscCs|�d||�S)z�
        Return the value of ``key`` within the hash ``name``

        For more information see https://redis.io/commands/hget
        ZHGETr,r�r1r1r2�hget�szHashCommands.hgetr�cCs|�d|�S)z�
        Return a Python dict of the hash's name/value pairs

        For more information see https://redis.io/commands/hgetall
        ZHGETALLr,rqr1r1r2�hgetall�szHashCommands.hgetallr&)r�ririr+cCs|�d|||�S)z�
        Increment the value of ``key`` in hash ``name`` by ``amount``

        For more information see https://redis.io/commands/hincrby
        ZHINCRBYr,�r.r�ririr1r1r2�hincrby�szHashCommands.hincrbyr�cCs|�d|||�S)z�
        Increment the value of ``key`` in hash ``name`` by floating ``amount``

        For more information see https://redis.io/commands/hincrbyfloat
        ZHINCRBYFLOATr,r�r1r1r2�hincrbyfloat�szHashCommands.hincrbyfloatcCs|�d|�S)z�
        Return the list of keys within hash ``name``

        For more information see https://redis.io/commands/hkeys
        ZHKEYSr,rqr1r1r2�hkeys�szHashCommands.hkeyscCs|�d|�S)z�
        Return the number of elements in hash ``name``

        For more information see https://redis.io/commands/hlen
        ZHLENr,rqr1r1r2�hlen�szHashCommands.hlenN)r�rir�r�r�r+cCsf|dur|s|std��|pg}|dur6|�||f�|rR|��D]}|�|�qB|jd|g|�R�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
        Nz'hset' with no key value pairsZHSET)rr�r�r-)r.r�rir�r�r�r�r1r1r2�hset�szHashCommands.hset)r�rir�r+cCs|�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
        ZHSETNXr,)r.r�rir�r1r1r2�hsetnx�szHashCommands.hsetnx)r�r�r+cCs`tj|jj�d|jj�d�tdd�|s0td��g}|��D]}|�|�q<|jd|g|�R�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.r�)�
stacklevelz"'hmset' with 'mapping' of length 0ZHMSET)	r�r�r@rpr�rr�r�r-)r.r�r�r�r�r1r1r2�hmset�s
��zHashCommands.hmset)r�rUr5r+cGst||�}|jd|g|�R�S)z�
        Returns a list of values ordered identically to ``keys``

        For more information see https://redis.io/commands/hmget
        ZHMGETrO)r.r�rUr5r1r1r2�hmgets
zHashCommands.hmgetcCs|�d|�S)z�
        Return the list of values within hash ``name``

        For more information see https://redis.io/commands/hvals
        ZHVALSr,rqr1r1r2�hvalsszHashCommands.hvalscCs|�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
        ZHSTRLENr,r�r1r1r2�hstrlenszHashCommands.hstrlen)r&)r�)NNNN)rprqrrrsrtr
rrr:r�rvr�rr�rpr�r�r:r�r�r�r�r�r�r�r�r�r�r1r1r1r2r�|sH	�
	����
�� 	 	r�c@sPeZdZdZded�dd�Zdeeedfee	e
dfedd�d	d
�ZdS)�Script�I
    An executable Lua script object returned by ``register_script``
    r(��registered_client�scriptcCs>||_||_t|t�r*|j��}|�|�}t�|��	�|_
dSr<�r�r�rGrt�connection_poolr`rb�hashlib�sha1�	hexdigest�sha�r.r�r�rer1r1r2rK%s


�Script.__init__N)r(N�rUr5rEcCs�|pg}|pg}|dur|j}t|�t|�}ddlm}t||�rP|j�|�z|j|jt	|�g|�R�WSt
y�|�|j�|_|j|jt	|�g|�R�YS0dS�z1Execute the script, passing any required ``args``Nr)�Pipeline�
r�r}r�rrG�scripts�add�evalshar�r�r�script_loadr��r.rUr5rErr1r1r2�__call__1s
�Script.__call__)NNN�rprqrrrsr"rKrr
r rrr	r1r1r1r2r� s��r�c@sPeZdZdZded�dd�Zdeeedfee	e
dfedd�d	d
�ZdS)�AsyncScriptr�rDr�cCs>||_||_t|t�r*|j��}|�|�}t�|��	�|_
dSr<r�r�r1r1r2rKRs


zAsyncScript.__init__N)rDNrc�s�|pg}|pg}|dur|j}t|�t|�}ddlm}t||�rP|j�|�z"|j|jt	|�g|�R�IdHWSt
y�|�|j�IdH|_|j|jt	|�g|�R�IdHYS0dSr)
r�r}�redis.asyncio.clientrrGrrrr�r�rrr�rr1r1r2r	^s
"zAsyncScript.__call__)NNNrr1r1r1r2rMs��rc@sReZdZdZeeed�dd�Zdeed�dd�Z	ed	�d
d�Z
eed�d
d�ZdS)�PubSubCommandszG
    Redis PubSub commands.
    see https://redis.io/topics/pubsub
    )rj�messager+cKs|jd||fi|��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
        ZPUBLISHr,)r.rjrr/r1r1r2�publish�szPubSubCommands.publishr�r�cKs|jd|fi|��S)z�
        Return a list of channels that have at least one subscriber

        For more information see https://redis.io/commands/pubsub-channels
        zPUBSUB CHANNELSr,r�r1r1r2�pubsub_channels�szPubSubCommands.pubsub_channelsr?cKs|jdi|��S)z�
        Returns the number of subscriptions to patterns

        For more information see https://redis.io/commands/pubsub-numpat
        �
PUBSUB NUMPAT)rr,rAr1r1r2�
pubsub_numpat�szPubSubCommands.pubsub_numpatr�cOs|jdg|�Ri|��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 NUMSUBr,rr1r1r2�
pubsub_numsub�szPubSubCommands.pubsub_numsubN)r�)rprqrrrsrrrurr!rrrr1r1r1r2rzs
	rc@sDeZdZdZeeeeeeeefd�dd�Z	eeeeeeefd�dd�Z
eeeeeeefd�dd	�Zeeeeeeeefd
�dd�Zeeeeeeefd
�dd�Z
eeeeeeefd
�dd�Zeed�dd�Zdd�dd�Zd'eededfed�dd�Zed�dd�Zeed �d!d"�Zd#eed$�d%d&�ZdS)(�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+cGs|j|||g|�R�Sr<r,)r.r�r�r�rr1r1r2�_eval�szScriptCommands._eval)r�r�rr+cGs|jd||g|�R�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
        ZEVAL�r�r.r�r�rr1r1r2�eval�s
zScriptCommands.evalcGs|jd||g|�R�S)aM
        The read-only variant of the EVAL command

        Execute the read-only Lue ``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
        ZEVAL_ROrrr1r1r2�eval_ro�szScriptCommands.eval_ro)r�r�r�rr+cGs|j|||g|�R�Sr<r,)r.r�r�r�rr1r1r2�_evalsha�szScriptCommands._evalsha)r�r�rr+cGs|jd||g|�R�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
        ZEVALSHA�r�r.r�r�rr1r1r2r�szScriptCommands.evalshacGs|jd||g|�R�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
        Z
EVALSHA_ROrrr1r1r2�
evalsha_ro�s
zScriptCommands.evalsha_ror�cGs|jdg|�R�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 EXISTSr,r�r1r1r2�
script_exists�szScriptCommands.script_existsNr?cGstd��dS)Nz<SCRIPT DEBUG is intentionally not implemented in the client.r�r�r1r1r2�script_debug�s�zScriptCommands.script_debugr��ASYNC)�	sync_typer+cCs6|dvrtd��|durg}n|g}|jdg|�R�S)z�Flush 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
        )r�r"NzpSCRIPT FLUSH defaults to SYNC in redis > 6.2, or accepts SYNC/ASYNC. For older versions, of redis leave as None.NzSCRIPT FLUSHr�)r.r#r0r1r1r2�script_flushs
�zScriptCommands.script_flushcCs
|�d�S)z�
        Kill the currently executing Lua script

        For more information see https://redis.io/commands/script-kill
        zSCRIPT KILLr,r~r1r1r2�script_killszScriptCommands.script_kill)r�r+cCs|�d|�S)z�
        Load a Lua ``script`` into the script cache. Returns the SHA.

        For more information see https://redis.io/commands/script-load
        zSCRIPT LOADr,�r.r�r1r1r2rszScriptCommands.script_loadr(�r.r�r+cCs
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&r1r1r2�register_script'szScriptCommands.register_script)N)rprqrrrsrtr:r�rrrrrrrrrur r!rr$r%r"rr�r)r1r1r1r2r�s:������
��rcs4eZdZdd��fdd�Zdeed�dd�Z�ZS)	�AsyncScriptCommandsNr?c�s
t���Sr<)r>r!r�r?r1r2r!2sz AsyncScriptCommands.script_debugrDr'cCs
t||�Sr()rr&r1r1r2r)5sz#AsyncScriptCommands.register_script)rprqrrr!r"rr)rAr1r1r?r2r*1sr*c@s"eZdZdZd!eeeeeeed�dd�Z	d"ee
e
eedfed�dd	�Z
ee
ed
�dd�Zee
ed
�d
d�Zd#eeeeeedfeeeeedfeedfeedfeedfeed�dd�Zd$ee
eeedfeeeeedfeedfeedfeedfeed�
dd�Zeeeedfed�dd�Zd%eee
dfeedfeedfeeedfeedfeedfeedfeedfeeeeed�dd�Zd&eeee
dfeedfeedfeeedfeedfeedfeedfeedfeeed�dd�Zeeeedfed�dd �ZdS)'�GeoCommandszr
    Redis Geospatial commands.
    see: https://redis.com/redis-best-practices/indexing-patterns/geospatial/
    F)r�rrurvr�r+cCst|r|rtd��t|�ddkr(td��|g}|r<|�d�|rJ|�d�|rX|�d�|�|�|jdg|�R�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�rz4GEOADD requires places with lon, lat and name valuesryrzZCHZGEOADD)rr�rHr�r-)r.r�rrurvr�r0r1r1r2�geoaddEs



zGeoCommands.geoaddN)r��place1�place2�unitr+cCs@|||g}|r |dvr td��n|r.|�|�|jdg|�R�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
        ��mZkm�miZftzGEODIST invalid unitZGEODISTrd)r.r�r.r/r0r0r1r1r2�geodistos


zGeoCommands.geodistr
cGs|jd|g|�R�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
        ZGEOHASHr,rr1r1r2�geohash�szGeoCommands.geohashcGs|jd|g|�R�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
        ZGEOPOSr,rr1r1r2�geopos�szGeoCommands.geopos)r��	longitude�latitude�radiusr0�withdist�	withcoord�withhashrEr)r!�
store_dist�anyr+cCs&|jd|||||||||	|
|||
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
        Z	GEORADIUS�	r0r:r;r<rEr)r!r=r>��_georadiusgeneric)r.r�r7r8r9r0r:r;r<rEr)r!r=r>r1r1r2�	georadius�s .�zGeoCommands.georadius)
r��memberr9r0r:r;r<rEr)r!r=r>r+c

Cs$|jd|||||||||	|
||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
        ZGEORADIUSBYMEMBERr?r@)
r.r�rCr9r0r:r;r<rEr)r!r=r>r1r1r2�georadiusbymember�s�zGeoCommands.georadiusbymember)r�r5r/r+cOs`t|�}|dr&|ddvr&td��n"|dr>|�|d�n
|�d�|drd|ddurdtd��dD]\}}||rh|�|�qh|ddur�|�d	|dg�|dr�|�d
�|dr�|ddkr�|�d�n |dd
kr�|�d
�ntd��|d�r|d�rtd��|d�r,|�d|dg�|d�rH|�d|dg�|j|g|�Ri|��S)Nr0r1zGEORADIUS invalid unitr2r>rEz+``any`` can't be provided without ``count``))r:ZWITHDIST)r;Z	WITHCOORD)r<ZWITHHASHr�ANYr)�ASC�DESCzGEORADIUS invalid sortr!r=z3GEORADIUS store and store_dist cant be set togetherr&�	STOREDIST)r�rrHr�r-�r.r�r5r/r0Zarg_nameZ	byte_reprr1r1r2rA�s8




zGeoCommands._georadiusgenericr2)r�rCr7r8r0r9�width�heightr)rEr>r;r:r<r+cCs,|jd|||||||||	|
|||
|ddd�S)aE
        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 farest and DESC for farest 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
        Z	GEOSEARCHN�rCr7r8r0r9rJrKr)rEr>r;r:r<r!r=��_geosearchgeneric)r.r�rCr7r8r0r9rJrKr)rEr>r;r:r<r1r1r2�	geosearch(s&4�zGeoCommands.geosearch)rar�rCr7r8r0r9rJrKr)rEr>�	storedistr+cCs.|jd|||||||||	|
||dddd|
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
        ZGEOSEARCHSTORENrLrM)r.rar�rCr7r8r0r9rJrKr)rEr>rPr1r1r2�geosearchstoreps(�zGeoCommands.geosearchstorecOs$t|�}|ddur4|ddus,|ddur4td��|drf|dsL|drTtd��|�d|dg�|dr�|dr�|�d|d|dg�|ddur�|d	dus�|d
dur�td��|ddur�td
��|d��dvr�td��|d�r$|d	�s|d
�rtd��|�d|d|dg�|d	�rV|d
�rV|�d|d	|d
|dg�|d�r�|d��dk�r~|�d�n&|d��dk�r�|�d�ntd��|d�r�|�d|dg�|d�r�|�d�n|d�r�td��dD]\}}||�r�|�|��q�|j|g|�Ri|��S)NrCr7r8z4GEOSEARCH must have member or longitude and latitudez?GEOSEARCH member and longitude or latitude cant be set togethers
FROMMEMBERs
FROMLONLATr9rJrKz.GEOSEARCH must have radius or width and heightr0zGEOSEARCH must have unitr1zGEOSEARCH invalid unitz9GEOSEARCH radius and width or height cant be set togethersBYRADIUSsBYBOXr)rFsASCrGr%zGEOSEARCH invalid sortrEr/r>sANYz1GEOSEARCH ``any`` can't be provided without count))r:sWITHDIST)r;s	WITHCOORD)r<sWITHHASH)r=rH)r�rr�r�rMrHr-rIr1r1r2rN�sZ��
�




zGeoCommands._geosearchgeneric)FFF)N)	NFFFNNNNF)	NFFFNNNNF)
NNNr2NNNNNFFFF)NNNr2NNNNNFF)rprqrrrsr r
rrvrur-rrrtr4r5r6r:r:rBrDrArOrQrNr1r1r1r2r+?s	��+��	�




�D�




�(�1�







�L�







�0�r+c@s�eZdZdZed�dd�Zdeeeeeeeed�dd�Z	ed�d	d
�Z
ed�dd�Zdd�d
d�Zed�dd�Z
ed�dd�Zed�dd�ZdS)�ModuleCommandszO
    Redis Module commands.
    see: https://redis.io/topics/modules-intro
    r?cGs|jd|g|�R�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
        zMODULE LOADr,)r.�pathr5r1r1r2�module_load�szModuleCommands.module_loadN)rSr�r5r+cCsPg}|dur |�d�|�|�|dur<|�d�|�|�|jd|g|�R�S)z�
        Loads a module from a dynamic library at runtime with configuration directives.

        For more information see https://redis.io/commands/module-loadex
        NZCONFIGZARGSz
MODULE LOADEXr�)r.rSr�r5r0r1r1r2�
module_loadex�s



zModuleCommands.module_loadexcCs|�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 UNLOADr,rqr1r1r2�
module_unload
szModuleCommands.module_unloadcCs
|�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
        zMODULE LISTr,r~r1r1r2�module_listszModuleCommands.module_listcCstd��dSr�r�r~r1r1r2r�s�zModuleCommands.command_infocCs
|�d�S)Nr�r,r~r1r1r2r�!szModuleCommands.command_countcGs|jdg|�R�S)NzCOMMAND GETKEYSr,r�r1r1r2�command_getkeys$szModuleCommands.command_getkeyscCs
|�d�S)Nr�r,r~r1r1r2r�'szModuleCommands.command)NN)rprqrrrsrurTrtrr
rUrVrWr�r�rXr�r1r1r1r2rR�s 
�

�		rRc@s0eZdZdZdd�Zggdfdd�Zdd�ZdS)	r�r�cCs<||_||_t|t�r(|��}|�|�}t�|���|_	dSr<)
r�r�rGrtr`rbr�r�r�r�r�r1r1r2rK0s

r�NcCs�|dur|j}t|�t|�}ddlm}t||�r@|j�|�z|j|jt	|�g|�R�WSt
y�|�|j�|_|j|jt	|�g|�R�YS0dSrrrr1r1r2r	<s
r
cCs0z|j��WSty*|jj��YS0dS)z4Get the encoder to encode string scripts into bytes.N)r�r`�AttributeErrorr�r~r1r1r2r`PszScript.get_encoder)rprqrrrsrKr	r`r1r1r1r2r�+scs"eZdZdd��fdd�Z�ZS)�AsyncModuleCommandsNr?c�s
t���Sr<r=r~r?r1r2r�dsz AsyncModuleCommands.command_info)rprqrrr�rAr1r1r?r2rZcsrZc@s:eZdZdZed�dd�Zed�dd�Zed�dd�Zd	S)
�ClusterCommandsz*
    Class for Redis Cluster commands
    r?cOs"|jd|����g|�Ri|��S)NzCLUSTER )r-rM)r.Zcluster_argr5r/r1r1r2�clustermszClusterCommands.clustercKs|jdi|��S)z�
        Disables read queries for a connection to a Redis Cluster slave node.

        For more information see https://redis.io/commands/readwrite
        �	READWRITE)r]r,rAr1r1r2�	readwritepszClusterCommands.readwritecKs|jdi|��S)z�
        Enables read queries for a connection to a Redis Cluster replica node.

        For more information see https://redis.io/commands/readonly
        �READONLY)r_r,rAr1r1r2�readonlyxszClusterCommands.readonlyN)rprqrrrsrur\r^r`r1r1r1r2r[hsr[c@speZdZdZd%eeeeeeefd�dd�Z	eeeeefd�dd�Z
d&eeeeefd
�dd�Zd'eeeeeeeefd�dd�Z
eeeeeeeefd�dd�Zeeeeeeefd�dd�Zeeeeeeefd�dd�Zeeeefd�dd�Zd(eeeeeeefd�dd�Zeeeefd�d d!�Zeeeefd�d"d#�Zd$S))�FunctionCommandsz!
    Redis Function commands
    F)�coderr+cCs*|r
dgng}|�|�|jdg|�R�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
        rhz
FUNCTION LOADrx)r.rbrr0r1r1r2�
function_load�s

zFunctionCommands.function_load)�libraryr+cCs|�d|�S)z�
        Delete the library called ``library`` and all its functions.

        For more information see https://redis.io/commands/function-delete
        zFUNCTION DELETEr,)r.rdr1r1r2�function_delete�sz FunctionCommands.function_deleter�r�cCs|�d|�S)zw
        Deletes all the libraries.

        For more information see https://redis.io/commands/function-flush
        zFUNCTION FLUSHr,r�r1r1r2�function_flush�szFunctionCommands.function_flushr�)rd�withcoder+cCs(d|g}|r|�d�|jdg|�R�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
        ZLIBRARYNAMEZWITHCODEz
FUNCTION LISTrx)r.rdrgr5r1r1r2�
function_list�s	
zFunctionCommands.function_list)r�r�rr+cGs|j|||g|�R�Sr<r,)r.r��functionr�rr1r1r2�_fcall�szFunctionCommands._fcall)r�rr+cGs|jd||g|�R�S)zf
        Invoke a function.

        For more information see https://redis.io/commands/fcall
        ZFCALL�rj�r.rir�rr1r1r2�fcall�szFunctionCommands.fcallcGs|jd||g|�R�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
        ZFCALL_ROrkrlr1r1r2�fcall_ro�s	zFunctionCommands.fcall_ror?cCs(ddlm}i}g||<|jdi|��S)z�
        Return the serialized payload of loaded libraries.

        For more information see https://redis.io/commands/function-dump
        rr��
FUNCTION DUMP)ror�r�r1r1r2�
function_dump�szFunctionCommands.function_dumprZ)�payload�policyr+cCs|�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
        zFUNCTION RESTOREr,)r.rqrrr1r1r2�function_restore�s
z!FunctionCommands.function_restorecCs
|�d�S)z�
        Kill a function that is currently executing.

        For more information see https://redis.io/commands/function-kill
        z
FUNCTION KILLr,r~r1r1r2�
function_kill�szFunctionCommands.function_killcCs
|�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
        zFUNCTION STATSr,r~r1r1r2�function_stats�szFunctionCommands.function_statsN)F)r�)r�F)rZ)rprqrrrsrtrrvrrrcrerfr
rhr:rjrmrnrprsrtrur1r1r1r2ra�s<��	��
�����rac@seZdZdZdS)�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�rprqrrrsr1r1r1r2rvsrvc@seZdZdZdS)�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.
    Nrwr1r1r1r2rxsrxc@seZdZdZdS)�CoreCommandsz�
    A class containing all of the implemented redis commands. This class is
    to be used as a mixin for synchronous Redis clients.
    Nrwr1r1r1r2ry"s
ryc@seZdZdZdS)�AsyncCoreCommandsz�
    A class containing all of the implemented redis commands. This class is
    to be used as a mixin for asynchronous Redis clients.
    Nrwr1r1r1r2rz2s
rz)Zr~r�r5r��typingrrrrrrrr	r
rrr
rrZredis.compatrZredis.exceptionsrrrrZredis.typingrrrrrrrrrrrr r!r"r#r$r%Zhelpersr'r
r(rDr�rur)ZAsyncACLCommandsrwr;rBrYr�r�ZAsyncListCommandsr+rIrLZAsyncSetCommandsreZAsyncStreamCommandsr�ZAsyncSortedSetCommandsr�ZAsyncHyperlogCommandsr�ZAsyncHashCommandsr�rrZAsyncPubSubCommandsrr*r+ZAsyncGeoCommandsrRrZr[ZAsyncClusterCommandsraZAsyncFunctionCommandsrvrxryrzr1r1r1r2�<module>s�@LO3pSSh*F "--)&F8y
�
�
�
�