HEX
Server: LiteSpeed
System: Linux us-phx-web1284.main-hosting.eu 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: u300739242 (300739242)
PHP: 8.2.30
Disabled: system, shell_exec, passthru, mysql_list_dbs, ini_alter, dl, symlink, link, chgrp, leak, popen, apache_child_terminate, virtual, mb_send_mail
Upload Files
File: //opt/alt/python311/lib/python3.11/site-packages/redis/commands/__pycache__/core.cpython-311.pyc
�

$�;f�|�
�X�ddlZddlZddlZddlZddlmZmZmZmZddl	m
Z
Gd�d��ZGd�d��ZGd	�d
��Z
Gd�d��ZGd
�d��ZGd�d��ZGd�d��ZGd�d��ZGd�d��ZGd�d��ZGd�d��ZGd�d��ZGd�d��ZGd�d ��ZGd!�d"��ZGd#�d$��ZGd%�d&��ZGd'�d(e
eeeeeeee��ZGd)�d*eeeeeee�	�	ZdS)+�N)�ConnectionError�	DataError�
NoScriptError�
RedisError�)�list_or_argsc�|�eZdZdZdd�Zd�Zdd�Zd�Zd�Zd�Z	dd	�Z
d
�Zd�Zd�Z
										dd�Zd�Zd�ZdS)�ACLCommandszX
    Redis Access Control List (ACL) commands.
    see: https://redis.io/topics/acl
    Nc�2�|r|gng}|jdg|�Ri|��S)aA
        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 check https://redis.io/commands/acl-cat
        zACL CAT��execute_command)�self�category�kwargs�piecess    �F/opt/alt/python311/lib/python3.11/site-packages/redis/commands/core.py�acl_catzACLCommands.acl_cats7�� (�/�(���R��#�t�#�I�A��A�A�A�&�A�A�A�c�$�|jdg|�Ri|��S)z�
        Delete the ACL for the specified ``username``s

        For more information check https://redis.io/commands/acl-deluser
        zACL DELUSERr�r�usernamers   r�acl_deluserzACLCommands.acl_delusers'��$�t�#�M�G�H�G�G�G��G�G�Grc��g}|�A	t|��}|dks|dkrt�n#t$rtd���wxYw|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�bitsrr�bs     r�acl_genpasszACLCommands.acl_genpass&s�������
���I�I���q�5�5�A��H�H�$�$�%���
�
�
��X����
����$�t�#�M�E�F�E�E�E�f�E�E�Es	�")�Ac� �|jd|fi|��S)z�
        Get the ACL details for the specified ``username``.

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

        For more information check https://redis.io/commands/acl-getuser
        zACL GETUSERrrs   r�acl_getuserzACLCommands.acl_getuser8s!��$�t�#�M�8�F�F�v�F�F�Frc��|jdi|��S)z�The ACL HELP command returns helpful text describing
        the different subcommands.

        For more information check https://redis.io/commands/acl-help
        �ACL HELP)r"r�rrs  r�acl_helpzACLCommands.acl_helpB���$�t�#�9�9�&�9�9�9rc��|jdi|��S)z�
        Return a list of all ACLs on the server

        For more information check https://redis.io/commands/acl-list
        �ACL LIST)r'rr#s  r�acl_listzACLCommands.acl_listJr%rc��g}|�9t|t��std���|�|��|jdg|�Ri|��S)z�
        Get ACL logs as a list.
        :param int count: Get logs[0:count].
        :rtype: List.

        For more information check https://redis.io/commands/acl-log
        Nz ACL LOG count must be an integer�ACL LOG)�
isinstancerr�appendr
)r�countr�argss    r�acl_logzACLCommands.acl_logRsf�������e�S�)�)�
G�� E�F�F�F��K�K�����#�t�#�I�?��?�?�?��?�?�?rc�*�dg}|jdg|�Ri|��S)z�
        Reset ACL logs.
        :rtype: Boolean.

        For more information check https://redis.io/commands/acl-log
        sRESETr*r)rrr.s   r�
acl_log_resetzACLCommands.acl_log_resetbs.���z��#�t�#�I�?��?�?�?��?�?�?rc��|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 check https://redis.io/commands/acl-load
        �ACL LOAD)r3rr#s  r�acl_loadzACLCommands.acl_loadl���$�t�#�9�9�&�9�9�9rc��|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 check https://redis.io/commands/acl-save
        �ACL SAVE)r7rr#s  r�acl_savezACLCommands.acl_savewr5rFc���|���}
|g}|	r|�d��|
r|�d��|r|�d��|r|�d��n|�d��|s|r|rtd���|r�t|g��}t	|��D]�\}}|
�|��}|�d��r!|�d|d	d
�z���P|�d��r!|�d|d	d
�z����td
|�d����|r�t|g��}t	|��D]�\}}|
�|��}|�d��r!|�d|d	d
�z���P|�d��r!|�d|d	d
�z����td|�d����|r|�d��|�r|D�]}|
�|��}|�d��r|�|���C|�d��r!|�d|d	d
�z���y|�d��r|�|����|�d��r!|�d|d	d
�z����td|
�|d����d����|r�|D]~}|
�|��}|�d��s=|�d��s(td|
�|d����d����|�|���|r2|D]/}|
�|��}|�d|z���0|jdg|�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 check https://redis.io/commands/acl-setuser
        sresets	resetkeyss	resetpasssonsoffz@Cannot set 'nopass' and supply 'passwords' or 'hashed_passwords'�+s>%srN�-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~%szACL SETUSER)	�get_encoderr,rr�	enumerate�encode�
startswith�decoder
)rr�enabled�nopass�	passwords�hashed_passwords�
categories�commands�keys�reset�
reset_keys�reset_passwordsr�encoderr�i�password�hashed_passwordr�cmd�keys                     r�acl_setuserzACLCommands.acl_setuser�s���X�"�"�$�$������	$��M�M�(�#�#�#��	(��M�M�,�'�'�'��	(��M�M�,�'�'�'��	"��M�M�%� � � � ��M�M�&�!�!�!��	�)�	�v�	��U���
��	�%�Y��3�3�I�(��3�3�

�

���8�"�>�>�(�3�3���&�&�t�,�,���M�M�&�8�A�B�B�<�"7�8�8�8�8��(�(��.�.���M�M�&�8�A�B�B�<�"7�8�8�8�8�#�9�A�9�9�9����
�	� ,�,<�b�A�A��&/�0@�&A�&A�

�

�"��?�")�.�.��"A�"A��"�-�-�d�3�3���M�M�&�?�1�2�2�+>�">�?�?�?�?�$�/�/��5�5���M�M�&�?�1�2�2�+>�">�?�?�?�?�#�9�1�9�9�9����
�	%��M�M�)�$�$�$��	�&�
�
��"�>�>�(�3�3���&�&�u�-�-���M�M�(�+�+�+�+��(�(��.�.�
��M�M�'�H�Q�R�R�L�"8�9�9�9�9��(�(��/�/���M�M�(�+�+�+�+��(�(��.�.���M�M�'�H�Q�R�R�L�"8�9�9�9�9�#�;�W�^�^�H�D�^�%I�%I�;�;�;�����	#��
#�
#���n�n�S�)�)���~�~�d�+�+��C�N�N�4�4H�4H��#�;�G�N�N�3�d�N�$C�$C�;�;�;�����
�
�c�"�"�"�"��	,��
,�
,���n�n�S�)�)���
�
�f�s�l�+�+�+�+�#�t�#�M�E�F�E�E�E�f�E�E�Erc��|jdi|��S)z�Returns a list of all registered users on the server.

        For more information check https://redis.io/commands/acl-users
        �	ACL USERS)rTrr#s  r�	acl_userszACLCommands.acl_users)s��
$�t�#�:�:�6�:�:�:rc��|jdi|��S)z}Get the username for the current connection

        For more information check https://redis.io/commands/acl-whoami
        �
ACL WHOAMI)rWrr#s  r�
acl_whoamizACLCommands.acl_whoami0s��
$�t�#�;�;�F�;�;�;r�N)
FFNNNNNFFF)�__name__�
__module__�__qualname__�__doc__rrrr r$r(r/r1r4r8rRrUrX�rrr
r
s3��������
B�B�B�B�H�H�H�F�F�F�F�$G�G�G�:�:�:�:�:�:�@�@�@�@� @�@�@�	:�	:�	:�	:�	:�	:�������
����eF�eF�eF�eF�N;�;�;�<�<�<�<�<rr
c���eZdZdZd�ZdAd�Zd�Zd�Z						dBd�Zd	�Z	dgfd
�Z
d�Zd�Zd
�Z
d�Zdgddddfd�Zdgddddfd�Zddgddddfd�Zd�Zd�ZdCd�ZdAd�Zd�Zd�Zd�Zd�ZdDd�Zd�Zd�Zd�Zd �Zd!�Zd"�Z d#�Z!dCd$�Z"dCd%�Z#d&�Z$d'�Z%d(�Z&d)�Z'dEd*�Z(d+�Z)d,�Z*d-�Z+			dFd.�Z,d/�Z-d0�Z.d1�Z/d2�Z0d3�Z1dEd4�Z2d5�Z3d6�Z4d7�Z5d8�Z6d9�Z7dGd:�Z8dHd;�Z9dEd<�Z:d=�Z;d>�Z<d?�Z=d@�Z>dS)I�ManagementCommandsz#
    Redis management commands
    c��|jdi|��S)z�Tell the Redis server to rewrite the AOF file from data in memory.

        For more information check https://redis.io/commands/bgrewriteaof
        �BGREWRITEAOF)rbrr#s  r�bgrewriteaofzManagementCommands.bgrewriteaof=s��
$�t�#�=�=�f�=�=�=rTc�V�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 check https://redis.io/commands/bgsave
        �SCHEDULE�BGSAVE�r,r
)r�schedulerrs    r�bgsavezManagementCommands.bgsaveDsF�����	&��M�M�*�%�%�%�#�t�#�H�@�v�@�@�@��@�@�@rc�,�|�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 check https://redis.io/commands/role
        �ROLEr�rs r�rolezManagementCommands.rolePs���#�#�F�+�+�+rc� �|jd|fi|��S)z�Disconnects the client at ``address`` (ip:port)

        For more information check https://redis.io/commands/client-kill
        �CLIENT KILLr)r�addressrs   r�client_killzManagementCommands.client_killZs!��
$�t�#�M�7�E�E�f�E�E�ErNc�X�g}|�Nd}	t|�����|	vrtd|	�����|�d|f��|�Qt	|t
��std���|r|�d��n|�d��|�|�d|f��|�|�d	|f��|�|�d
|f��|�|�d|f��|std���|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�master�slave�pubsubz CLIENT KILL type must be one of �TYPEz!CLIENT KILL skipme must be a bool)�SKIPMEsYES)rx�NO�IDsADDRsLADDRsUSERzVCLIENT KILL <filter> <value> ... ... <filter> <value> must specify at least one filterro)�str�lowerr�extendr+�boolr
)
r�_id�_type�addr�skipme�laddr�userrr.�client_typess
          r�client_kill_filterz%ManagementCommands.client_kill_filterasl��,����B�L��5�z�z���!�!��5�5�� S�<� S� S�T�T�T��K�K��%�(�)�)�)����f�d�+�+�
E�� C�D�D�D��
0����/�0�0�0�0����.�/�/�/��?��K�K����%�%�%����K�K��$��(�(�(����K�K��5�)�*�*�*����K�K��$��(�(�(��	��;���
�$�t�#�M�C�D�C�C�C�F�C�C�Crc��|jdi|��S)z�
        Returns information and statistics about the current
        client connection.

        For more information check https://redis.io/commands/client-info
        �CLIENT INFO)r�rr#s  r�client_infozManagementCommands.client_info�s��$�t�#�<�<�V�<�<�<rc��g}|�ad}t|�����|vrtd|�����|�d��|�|��t	|t
��std���|gkr=|�d��|�d�|����|jdg|�Ri|��S)	al
        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 check https://redis.io/commands/client-list
        N)rsrt�replicarvz!CLIENT LIST _type must be one of rwzclient_id must be a listrz� zCLIENT LIST)r{r|rr,r+�list�joinr
)rr��	client_idrr.r�s      r�client_listzManagementCommands.client_list�s�������D�L��5�z�z���!�!��5�5�� T�L� T� T�U�U�U��K�K�� � � ��K�K������)�T�*�*�	8��6�7�7�7���?�?��K�K������K�K�����+�+�,�,�,�#�t�#�M�C�D�C�C�C�F�C�C�Crc��|jdi|��S)z�
        Returns the current connection name

        For more information check https://redis.io/commands/client-getname
        �CLIENT GETNAME)r�rr#s  r�client_getnamez!ManagementCommands.client_getname����$�t�#�?�?��?�?�?rc��|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r#s  r�client_getredirz"ManagementCommands.client_getredir�s��$�t�#�@�@��@�@�@rc�T�gd�}||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
        )�ON�OFF�SKIPzCLIENT REPLY must be one of zCLIENT REPLY�rr
)r�replyr�repliess    r�client_replyzManagementCommands.client_reply�sN�� (�'�'�������F�7�F�F�G�G�G�#�t�#�N�E�D�D�V�D�D�Drc��|jdi|��S)z{
        Returns the current connection id

        For more information check https://redis.io/commands/client-id
        �	CLIENT ID)r�rr#s  rr�zManagementCommands.client_id����$�t�#�:�:�6�:�:�:rFc	�8�|�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�clientid�prefix�bcast�optin�optout�noloops       r�client_tracking_onz%ManagementCommands.client_tracking_on�s+���#�#��(�F�E�5�&�&�
�
�	
rc	�8�|�d||||||��S)z�
        Turn off the tracking mode.
        For more information about the options look at client_tracking func.

        See https://redis.io/commands/client-tracking
        Fr�r�s       r�client_tracking_offz&ManagementCommands.client_tracking_off�s+���#�#��8�V�U�E�6�6�
�
�	
rc��t|��dkr|durtd���|rdgndg}	|�|	�d|g��|D]}
|	�d|
g���|r|	�d	��|r|	�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�N�REDIRECT�PREFIX�BCAST�OPTIN�OPTOUT�NOLOOPzCLIENT TRACKING)�lenrr}r,r
)r�onr�r�r�r�r�r�rr�ps           rr�z"ManagementCommands.client_trackings��R�v�;�;�!��������@�A�A�A��*�$���E�7�����M�M�:�x�0�1�1�1��	)�	)�A��M�M�8�Q�-�(�(�(�(��	#��M�M�'�"�"�"��	#��M�M�'�"�"�"��	$��M�M�(�#�#�#��	$��M�M�(�#�#�#�#�t�#�$5�?��?�?�?�?rc��|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r#s  r�client_trackinginfoz&ManagementCommands.client_trackinginfoDs��$�t�#�D�D�V�D�D�Drc� �|jd|fi|��S)z
        Sets the current connection name

        For more information check https://redis.io/commands/client-setname
        zCLIENT SETNAMEr)r�namers   r�client_setnamez!ManagementCommands.client_setnameMs"��$�t�#�$4�d�E�E�f�E�E�Erc�l�dt|��g}|r|�d��|j|i|��S)aD
        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 check https://redis.io/commands/client-unblock
        zCLIENT UNBLOCKsERROR)rr,r
)rr��errorrr.s     r�client_unblockz!ManagementCommands.client_unblockUsF��!�#�i�.�.�1���	"��K�K��!�!�!�#�t�#�T�4�V�4�4�4rc��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 check 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 integer�WRITE)r{r+rrr,r
)r�timeout�allrr.s     r�client_pausezManagementCommands.client_pausecsh�� ��G���-���'�3�'�'�	G��E�F�F�F��	!��K�K�� � � �#�t�#�T�4�V�4�4�4rc��|jdi|��S)zx
        Unpause all redis clients

        For more information check https://redis.io/commands/client-unpause
        �CLIENT UNPAUSE)r�rr#s  r�client_unpausez!ManagementCommands.client_unpausezr�rc��|jdi|��S)z�
        Returns dict reply of details about all Redis commands.

        For more information check https://redis.io/commands/command
        �COMMAND)r�rr#s  r�commandzManagementCommands.command�s��$�t�#�8�8��8�8�8rc� �td����Nz<COMMAND INFO is intentionally not implemented in the client.��NotImplementedErrorr#s  r�command_infozManagementCommands.command_info����!�J�
�
�	
rc��|jdi|��S)N�
COMMAND COUNT)r�rr#s  r�
command_countz ManagementCommands.command_count�s��#�t�#�>�>�v�>�>�>r�*c� �|jd|fi|��S)z�
        Return a dictionary of configuration based on the ``pattern``

        For more information check https://redis.io/commands/config-get
        z
CONFIG GETr�r�patternrs   r�
config_getzManagementCommands.config_get�s!��$�t�#�L�'�D�D�V�D�D�Drc�"�|jd||fi|��S)zySet config item ``name`` with ``value``

        For more information check https://redis.io/commands/config-set
        z
CONFIG SETr)rr��valuers    r�
config_setzManagementCommands.config_set�s#��
$�t�#�L�$��H�H��H�H�Hrc��|jdi|��S)zy
        Reset runtime statistics

        For more information check https://redis.io/commands/config-resetstat
        �CONFIG RESETSTAT)r�rr#s  r�config_resetstatz#ManagementCommands.config_resetstat�s��$�t�#�A�A�&�A�A�Arc��|jdi|��S)z�
        Rewrite config file with the minimal change to reflect running config.

        For more information check https://redis.io/commands/config-rewrite
        �CONFIG REWRITE)r�rr#s  r�config_rewritez!ManagementCommands.config_rewrite�r�rc��|jdi|��S)z�
        Returns the number of keys in the current database

        For more information check https://redis.io/commands/dbsize
        �DBSIZE)r�rr#s  r�dbsizezManagementCommands.dbsize�s��$�t�#�7�7��7�7�7rc� �|jd|fi|��S)z�
        Returns version specific meta information about a given key

        For more information check https://redis.io/commands/debug-object
        zDEBUG OBJECTr)rrQrs   r�debug_objectzManagementCommands.debug_object�s!��$�t�#�N�C�B�B�6�B�B�Brc� �td���)Nz�
            DEBUG SEGFAULT is intentionally not implemented in the client.

            For more information check https://redis.io/commands/debug-segfault
            r�r#s  r�debug_segfaultz!ManagementCommands.debug_segfault����!�
�
�
�	
rc� �|jd|fi|��S)zy
        Echo the string back from the server

        For more information check https://redis.io/commands/echo
        �ECHOr)rr�rs   r�echozManagementCommands.echo�s!��$�t�#�F�E�<�<�V�<�<�<rc�V�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 check https://redis.io/commands/flushall
        �ASYNC�FLUSHALLrg�r�asynchronousrr.s    r�flushallzManagementCommands.flushall�sF�����	"��K�K��!�!�!�#�t�#�J�@��@�@�@��@�@�@rc�V�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 check https://redis.io/commands/flushdb
        r��FLUSHDBrgr�s    r�flushdbzManagementCommands.flushdb�sF�����	"��K�K��!�!�!�#�t�#�I�?��?�?�?��?�?�?rc�6�ddlm}i}g||<|jdi|��S)z�
        Initiates a replication stream from the master.

        For more information check https://redis.io/commands/sync
        r��NEVER_DECODE�SYNC)r���redis.clientr�r
)rr��optionss   r�synczManagementCommands.sync�s>��	.�-�-�-�-�-��� "����#�t�#�6�6�g�6�6�6rc�<�ddlm}i}g||<|jd||fi|��S)z�
        Initiates a replication stream from the master.
        Newer version for `sync`.

        For more information check https://redis.io/commands/sync
        rr��PSYNCr�)r�
replicationid�offsetr�r�s     r�psynczManagementCommands.psync�sD��	.�-�-�-�-�-��� "����#�t�#�G�]�F�N�N�g�N�N�Nrc�"�|jd||fi|��S)zi
        Swap two databases

        For more information check https://redis.io/commands/swapdb
        �SWAPDBr)r�first�secondrs    r�swapdbzManagementCommands.swapdbs#��$�t�#�H�e�V�F�F�v�F�F�Frc� �|jd|fi|��S)zcSelect the Redis logical database at index.

        See: https://redis.io/commands/select
        �SELECTr)r�indexrs   r�selectzManagementCommands.selects!��
$�t�#�H�e�>�>�v�>�>�>rc�>�|�
|jdi|��S|jd|fi|��S)ao
        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 check https://redis.io/commands/info
        N�INFO)rr)r�sectionrs   r�infozManagementCommands.infos?���?�'�4�'�9�9�&�9�9�9�'�4�'���B�B�6�B�B�Brc��|jdi|��S)z�
        Return a Python datetime object representing the last time the
        Redis database was saved to disk

        For more information check https://redis.io/commands/lastsave
        �LASTSAVE)rrr#s  r�lastsavezManagementCommands.lastsave's��$�t�#�9�9�&�9�9�9rc�B�|r|jdg|�Ri|��S|jdi|��S)z}
        Get the Redis version and a piece of generative computer art

        See: https://redis.io/commands/lolwut
        zLOLWUT VERSION�LOLWUTN)rr)r�version_numbersrs   r�lolwutzManagementCommands.lolwut0sI���	<�'�4�'�(8�U�?�U�U�U�f�U�U�U�'�4�'�;�;�F�;�;�;rc�,�|�d��S)zuPerform a full reset on the connection's server side contenxt.

        See: https://redis.io/commands/reset
        �RESETrrls rrIzManagementCommands.reset;s��
�#�#�G�,�,�,rc	�|�t|g��}|std���g}
|r|
�d��|r|
�d��|r*|
�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 check https://redis.io/commands/migrate
        z!MIGRATE requires at least one keysCOPYsREPLACEsAUTHsKEYS�MIGRATE�)rrr,r}r
)r�host�portrH�destination_dbr��copy�replace�authrrs           r�migratezManagementCommands.migrateBs���>�D�"�%�%���	A��?�@�@�@����	#��M�M�'�"�"�"��	&��M�M�*�%�%�%��	 ��M�M�'�"�"�"��M�M�$�����
�
�g�����
�
�d����#�t�#��t�T�2�~�w�
�AG�
�
�
�KQ�
�
�	
rc�&�|jd||fd|i|��S)zJ
        Return the encoding, idletime, or refcount about the key
        �OBJECT�infotyper)rr(rQrs    r�objectzManagementCommands.objectrs7��$�t�#��h��
�
�.6�
�:@�
�
�	
rc� �td���)Nz�
            MEMORY DOCTOR is intentionally not implemented in the client.

            For more information check https://redis.io/commands/memory-doctor
            r�r#s  r�
memory_doctorz ManagementCommands.memory_doctorzr�rc� �td���)Nz�
            MEMORY HELP is intentionally not implemented in the client.

            For more information check https://redis.io/commands/memory-help
            r�r#s  r�memory_helpzManagementCommands.memory_help�r�rc��|jdi|��S)z�
        Return a dictionary of memory stats

        For more information check https://redis.io/commands/memory-stats
        �MEMORY STATS)r/rr#s  r�memory_statszManagementCommands.memory_stats����$�t�#�=�=�f�=�=�=rc��|jdi|��S)z�
        Return an internal statistics report from the memory allocator.

        See: https://redis.io/commands/memory-malloc-stats
        �MEMORY MALLOC-STATS)r3rr#s  r�memory_malloc_statsz&ManagementCommands.memory_malloc_stats�s��$�t�#�D�D�V�D�D�Drc��g}t|t��r|�d|g��|jd|g|�Ri|��S)ar
        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 check https://redis.io/commands/memory-usage
        sSAMPLESzMEMORY USAGE)r+rr}r
)rrQ�samplesrr.s     r�memory_usagezManagementCommands.memory_usage�sW�����g�s�#�#�	/��K�K��W�-�.�.�.�#�t�#�N�C�I�$�I�I�I�&�I�I�Irc��|jdi|��S)z�
        Attempts to purge dirty pages for reclamation by allocator

        For more information check https://redis.io/commands/memory-purge
        �MEMORY PURGE)r9rr#s  r�memory_purgezManagementCommands.memory_purge�r1rc��|jdi|��S)zj
        Ping the Redis server

        For more information check https://redis.io/commands/ping
        �PING)r<rr#s  r�pingzManagementCommands.ping����$�t�#�5�5�f�5�5�5rc��|jdi|��S)z|
        Ask the server to close the connection.

        For more information check https://redis.io/commands/quit
        �QUIT)r@rr#s  r�quitzManagementCommands.quit�r>rc�$�|jdg|�Ri|��S)a2
        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 check  https://redis.io/commands/replicaof
        �	REPLICAOFr�rr.rs   r�	replicaofzManagementCommands.replicaof�s'��$�t�#�K�A�$�A�A�A�&�A�A�Arc��|jdi|��S)z�
        Tell the Redis server to save its data to disk,
        blocking until the save is complete

        For more information check https://redis.io/commands/save
        �SAVE)rGrr#s  r�savezManagementCommands.save����$�t�#�5�5�f�5�5�5rc���|r|rtd���dg}|r|�d��|r|�d��	|j|i|��n#t$rYdSwxYwt	d���)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 check https://redis.io/commands/shutdown
        z+SHUTDOWN save and nosave cannot both be set�SHUTDOWNrG�NOSAVENzSHUTDOWN seems to have failed.)rr,r
rr)rrH�nosaverr.s     r�shutdownzManagementCommands.shutdown�s����	K�F�	K��I�J�J�J��|���	 ��K�K������	"��K�K��!�!�!�	� �D� �$�1�&�1�1�1�1���	�	�	��F�F�	�����9�:�:�:s�
A�
A"�!A"c�D�|�|�
|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 check https://redis.io/commands/slaveof
        N)�SLAVEOFrysONErPr)rrr rs    r�slaveofzManagementCommands.slaveof�sE���<�D�L�'�4�'�K�K�F�K�K�K�#�t�#�I�t�T�D�D�V�D�D�Drc��ddlm}dg}|�|�|��|����dd��}|durg||<|j|i|��S)z�
        Get the entries from the slowlog. If ``num`` is specified, get the
        most recent ``num`` items.

        For more information check https://redis.io/commands/slowlog-get
        rr�zSLOWLOG GETN�decode_responsesFT)r�r�r,�get_connection_kwargs�getr
)r�numrr�r.rSs      r�slowlog_getzManagementCommands.slowlog_get�s���	.�-�-�-�-�-�����?��K�K������5�5�7�7�;�;�<N�PU�V�V���t�#�#�#%�F�<� �#�t�#�T�4�V�4�4�4rc��|jdi|��S)z�
        Get the number of items in the slowlog

        For more information check https://redis.io/commands/slowlog-len
        �SLOWLOG LEN)rYrr#s  r�slowlog_lenzManagementCommands.slowlog_lens��$�t�#�<�<�V�<�<�<rc��|jdi|��S)z}
        Remove all items in the slowlog

        For more information check https://redis.io/commands/slowlog-reset
        �
SLOWLOG RESET)r\rr#s  r�
slowlog_resetz ManagementCommands.slowlog_reset���$�t�#�>�>�v�>�>�>rc��|jdi|��S)z�
        Returns the server time as a 2-item tuple of ints:
        (seconds since epoch, microseconds into this second).

        For more information check https://redis.io/commands/time
        �TIME)r`rr#s  r�timezManagementCommands.timerIrc�"�|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 check https://redis.io/commands/wait
        �WAITr)r�num_replicasr�rs    r�waitzManagementCommands.wait%s#��$�t�#�F�L�'�L�L�V�L�L�Lr)T)NNNNNN�F�r�rY)FFN)FF�NN)?rZr[r\r]rcrirmrqr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrr
rrrrrIr%r)r+r-r0r4r7r:r=rArErHrNrQrWrZr]rarer^rrr`r`8s���������>�>�>�
A�
A�
A�
A�,�,�,�F�F�F�
��
���
�0D�0D�0D�0D�d=�=�=�!%��D�D�D�D�0@�@�@�A�A�A�E�E�E�*;�;�;�������
�
�
�
�*������
�
�
�
�*�������:@�:@�:@�:@�xE�E�E�F�F�F�5�5�5�5�5�5�5�5�.@�@�@�9�9�9�
�
�
�
?�?�?�E�E�E�E�I�I�I�B�B�B�@�@�@�8�8�8�C�C�C�
�
�
�=�=�=�A�A�A�A�@�@�@�@�
7�
7�
7�O�O�O�G�G�G�?�?�?�C�C�C�C�":�:�:�	<�	<�	<�-�-�-���
�.
�.
�.
�.
�`
�
�
�
�
�
�
�
�
�>�>�>�E�E�E�J�J�J�J� >�>�>�6�6�6�6�6�6�	B�	B�	B�6�6�6�;�;�;�;�.
E�
E�
E�
E�5�5�5�5�"=�=�=�?�?�?�6�6�6�	M�	M�	M�	M�	Mrr`c��eZdZdZd�ZdAd�ZdBd�Zd�ZdAd�ZdCd	�Z	dDd�Z
e
Zd�Zd
�Z
d�Zd�ZeZd�Zd�Zd�Zd�ZdEd�Zd�Zd�Zd�Zd�ZdDd�ZeZdFd�ZdGd�ZdHd �ZdHd!�Zd"�Z d#�Z!d$�Z"d%�Z#d&�Z$d'�Z%d(�Z&d)�Z'd*�Z(dCd+�Z)d,�Z*d-�Z+d.�Z,				dId/�Z-								dJd0�Z.d1�Z/d2�Z0d3�Z1d4�Z2d5�Z3					dKd7�Z4d8�Z5dLd:�Z6d;�Z7d<�Z8d=�Z9d>�Z:d?�Z;d@�Z<dS)M�BasicKeyCommandsz(
    Redis basic key-based commands
    c�0�|�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 check https://redis.io/commands/append
        �APPENDr)rrQr�s   rr,zBasicKeyCommands.append6s���#�#�H�c�5�9�9�9rNc��|g}|�-|�+|�|��|�|��n|�|�|�|�td���|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 check https://redis.io/commands/bitcount
        Nz$Both start and end must be specified�BITCOUNT)r,rr
)rrQ�start�end�paramss     r�bitcountzBasicKeyCommands.bitcount@sx����������M�M�%� � � ��M�M�#�������C�K�S�_����B�C�C�C�#�t�#�J�8��8�8�8�8rc�&�t|||���S)z�
        Return a BitFieldOperation instance to conveniently construct one or
        more bitfield operations on ``key``.

        For more information check https://redis.io/commands/bitfield
        )�default_overflow)�BitFieldOperation)rrQrts   r�bitfieldzBasicKeyCommands.bitfieldOs��!��s�=M�N�N�N�Nrc�"�|jd||g|�R�S)z�
        Perform a bitwise operation using ``operation`` between ``keys`` and
        store the result in ``dest``.

        For more information check https://redis.io/commands/bitop
        �BITOPr)r�	operation�destrHs    r�bitopzBasicKeyCommands.bitopXs#��$�t�#�G�Y��D�t�D�D�D�Drc���|dvrtd���||g}|duo|�|��|�|�|�|��n|�|�td���|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 check https://redis.io/commands/bitpos
        )rrzbit must be 0 or 1Nz0start argument is not set, when end is specified�BITPOS�rr,r
)rrQ�bitrorprqs      r�bitposzBasicKeyCommands.bitposas����f����0�1�1�1��s���
�T��2�f�m�m�E�2�2�������M�M�#�����
�]�s���Q�R�R�R�#�t�#�H�6�v�6�6�6�6rFc��||g}|�|�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 check https://redis.io/commands/copy
        N�DB�REPLACE�COPY)r}r,r
)r�source�destinationr!r#rqs      rr"zBasicKeyCommands.copyvs`���+�&���%��M�M�4��0�1�1�1��	%��M�M�)�$�$�$�#�t�#�F�4�V�4�4�4�4rrc�0�|�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 check https://redis.io/commands/decrby
        �DECRBYr�rr��amounts   r�decrbyzBasicKeyCommands.decrby�����#�#�H�d�F�;�;�;rc��|jdg|�R�S)z@
        Delete one or more keys specified by ``names``
        �DELr�r�namess  r�deletezBasicKeyCommands.delete�s��$�t�#�E�2�E�2�2�2�2rc�0�|�|��dSrY)r��rr�s  r�__delitem__zBasicKeyCommands.__delitem__�s�����D�����rc�:�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 check https://redis.io/commands/dump
        rr��DUMPr�)rr�r�r�s    r�dumpzBasicKeyCommands.dump�sB��	.�-�-�-�-�-��� "����#�t�#�F�D�<�<�G�<�<�<rc��|jdg|�R�S)z�
        Returns the number of ``names`` that exist

        For more information check https://redis.io/commands/exists
        �EXISTSrr�s  r�existszBasicKeyCommands.exists����$�t�#�H�5�u�5�5�5�5rc��t|tj��rt|j����}|�d||��S)z�
        Set an expire flag on key ``name`` for ``time`` seconds. ``time``
        can be represented by an integer or a Python timedelta object.

        For more information check https://redis.io/commands/expire
        �EXPIRE�r+�datetime�	timedeltar�
total_secondsr
�rr�ras   r�expirezBasicKeyCommands.expire�sJ���d�H�.�/�/�	-��)�t�)�+�+�,�,�D��#�#�H�d�D�9�9�9rc���t|tj��r3ttj|�������}|�d||��S)z�
        Set an expire flag on key ``name``. ``when`` can be represented
        as an integer indicating unix time or a Python datetime object.

        For more information check https://redis.io/commands/expireat
        �EXPIREAT)r+r�rra�mktime�	timetupler
)rr��whens   r�expireatzBasicKeyCommands.expireat�sR���d�H�-�.�.�	6��t�{�4�>�>�#3�#3�4�4�5�5�D��#�#�J��d�;�;�;rc�.�|�d|��S)z�
        Return the value at key ``name``, or None if the key doesn't exist

        For more information check https://redis.io/commands/get
        �GETrr�s  rrUzBasicKeyCommands.get�����#�#�E�4�0�0�0rc�.�|�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 check https://redis.io/commands/getdel
        �GETDELrr�s  r�getdelzBasicKeyCommands.getdel�s���#�#�H�d�3�3�3rc��||||h}t|��dkst|��dkr|rtd���g}|�e|�d��t|tj��r!t
|�����}|�|��|�h|�d��t|tj��r$t
|���dz��}|�|��|��|�d��t|tj��rMt
|jd	z��}	t
tj
|�������|	z}|�|��|��|�d
��t|tj��rPt
|jdz��}
t
tj
|�������dz|
z}|�|��|r|�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 check https://redis.io/commands/getex
        �rzK``ex``, ``px``, ``exat``, ``pxat``, and ``persist`` are mutually exclusive.N�EX�PX���EXAT�@B�PXAT�PERSIST�GETEX)
r�rr,r+r�r�rr��microsecondrar�r�r
)rr��ex�px�exat�pxat�persist�opsetr�s�mss           r�getexzBasicKeyCommands.getex�s5��,�R��t�$���u�:�:��>�>�S��Z�Z�!�^�^��^��:���
�
��
�>��M�M�$�����"�h�0�1�1�
-���)�)�+�+�,�,���M�M�"����
�>��M�M�$�����"�h�0�1�1�
4���)�)�+�+�d�2�3�3���M�M�"�������M�M�&�!�!�!��$�� 1�2�2�
>���(�7�2�3�3���4�;�t�~�~�'7�'7�8�8�9�9�A�=���M�M�$�������M�M�&�!�!�!��$�� 1�2�2�
F���)�D�0�1�1���4�;�t�~�~�'7�'7�8�8�9�9�D�@�2�E���M�M�$�����	%��M�M�)�$�$�$�#�t�#�G�T�;�F�;�;�;�;rc�R�|�|��}|�|St|���)zg
        Return the value at key ``name``, raises a KeyError if the key
        doesn't exist.
        )rU�KeyError�rr�r�s   r�__getitem__zBasicKeyCommands.__getitem__s*��
����������L��t�n�n�rc�0�|�d||��S)z�
        Returns a boolean indicating the value of ``offset`` in ``name``

        For more information check https://redis.io/commands/getbit
        �GETBITr)rr�rs   r�getbitzBasicKeyCommands.getbit#s���#�#�H�d�F�;�;�;rc�2�|�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 check https://redis.io/commands/getrange
        �GETRANGEr)rrQrorps    r�getrangezBasicKeyCommands.getrange+s���#�#�J��U�C�@�@�@rc�0�|�d||��S)a3
        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 check https://redis.io/commands/getset
        �GETSETrr�s   r�getsetzBasicKeyCommands.getset4s���#�#�H�d�E�:�:�:rc�0�|�d||��S)z�
        Increments the value of ``key`` by ``amount``.  If no key exists,
        the value will be initialized as ``amount``

        For more information check https://redis.io/commands/incrby
        �INCRBYrr�s   r�incrbyzBasicKeyCommands.incrby@r�r��?c�0�|�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 check https://redis.io/commands/incrbyfloat
        �INCRBYFLOATrr�s   r�incrbyfloatzBasicKeyCommands.incrbyfloatKs���#�#�M�4��@�@�@rr�c� �|jd|fi|��S)z�
        Returns a list of keys matching ``pattern``

        For more information check https://redis.io/commands/keys
        �KEYSrr�s   rrHzBasicKeyCommands.keysTs!��$�t�#�F�G�>�>�v�>�>�>r�LEFT�RIGHTc�*�||||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 check https://redis.io/commands/lmove
        �LMOVEr)r�
first_list�second_list�srcrzrqs      r�lmovezBasicKeyCommands.lmove\s-���k�3��5��#�t�#�G�5�f�5�5�5�5rc�,�|||||g}|jdg|�R�S)zq
        Blocking version of lmove.

        For more information check https://redis.io/commands/blmove
        �BLMOVEr)rr�r�r�r�rzrqs       r�blmovezBasicKeyCommands.blmovegs/���k�3��g�>��#�t�#�H�6�v�6�6�6�6rc�b�ddlm}t||��}i}|sg||<|jdg|�Ri|��S)z�
        Returns a list of values ordered identically to ``keys``

        For more information check https://redis.io/commands/mget
        r)�EMPTY_RESPONSE�MGET)r�r�rr
)rrHr.r�r�s     r�mgetzBasicKeyCommands.mgetps_��	0�/�/�/�/�/��D�$�'�'�����	)�&(�G�N�#�#�t�#�F�=�T�=�=�=�W�=�=�=rc�z�g}|���D]}|�|���|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 check https://redis.io/commands/mset
        �MSET��itemsr}r
�r�mappingr��pairs    r�msetzBasicKeyCommands.mset~sP�����M�M�O�O�	�	�D��L�L������#�t�#�F�3�U�3�3�3�3rc�z�g}|���D]}|�|���|jdg|�R�S)ax
        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 check https://redis.io/commands/msetnx
        �MSETNXr�r�s    r�msetnxzBasicKeyCommands.msetnx�sP�����M�M�O�O�	�	�D��L�L������#�t�#�H�5�u�5�5�5�5rc�0�|�d||��S)z�
        Moves the key ``name`` to a different Redis database ``db``

        For more information check https://redis.io/commands/move
        �MOVEr)rr��dbs   r�movezBasicKeyCommands.move�s���#�#�F�D�"�5�5�5rc�.�|�d|��S)zy
        Removes an expiration on ``name``

        For more information check https://redis.io/commands/persist
        r�rr�s  rr�zBasicKeyCommands.persist�����#�#�I�t�4�4�4rc��t|tj��rt|j��dz��}|�d||��S)z�
        Set an expire flag on key ``name`` for ``time`` milliseconds.
        ``time`` can be represented by an integer or a Python timedelta
        object.

        For more information check https://redis.io/commands/pexpire
        r��PEXPIREr�r�s   r�pexpirezBasicKeyCommands.pexpire�sO���d�H�.�/�/�	4��)�t�)�+�+�d�2�3�3�D��#�#�I�t�T�:�:�:rc��t|tj��rPt|jdz��}tt	j|�������dz|z}|�d||��S)a
        Set an expire flag on key ``name``. ``when`` can be represented
        as an integer representing unix time in milliseconds (unix time * 1000)
        or a Python datetime object.

        For more information check https://redis.io/commands/pexpireat
        r��	PEXPIREAT)r+r�rr�rar�r�r
)rr�r�r�s    r�	pexpireatzBasicKeyCommands.pexpireat�sr���d�H�-�.�.�	B��T�%��,�-�-�B��t�{�4�>�>�#3�#3�4�4�5�5��<�r�A�D��#�#�K��t�<�<�<rc��t|tj��r$t|���dz��}|�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 check https://redis.io/commands/psetex
        r��PSETEXr�)rr��time_msr�s    r�psetexzBasicKeyCommands.psetex�sQ���g�x�1�2�2�	:��'�/�/�1�1�D�8�9�9�G��#�#�H�d�G�U�C�C�Crc�.�|�d|��S)z�
        Returns the number of milliseconds until the key ``name`` will expire

        For more information check https://redis.io/commands/pttl
        �PTTLrr�s  r�pttlzBasicKeyCommands.pttl�����#�#�F�D�1�1�1rc��g}|�|�|��|r|�d��|jd|g|�R�S)ar
        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 check https://redis.io/commands/hrandfield
        N�
WITHVALUES�
HRANDFIELDrg)rrQr-�
withvaluesrqs     r�
hrandfieldzBasicKeyCommands.hrandfield�sX�������M�M�%� � � ��	(��M�M�,�'�'�'�#�t�#�L�#�?��?�?�?�?rc��|jdi|��S)zz
        Returns the name of a random key

        For more information check https://redis.io/commands/randomkey
        �	RANDOMKEY)rrr#s  r�	randomkeyzBasicKeyCommands.randomkey�r�rc�0�|�d||��S)zt
        Rename key ``src`` to ``dst``

        For more information check https://redis.io/commands/rename
        �RENAMEr�rr��dsts   r�renamezBasicKeyCommands.rename�s���#�#�H�c�3�7�7�7rc�0�|�d||��S)z�
        Rename key ``src`` to ``dst`` if ``dst`` doesn't already exist

        For more information check https://redis.io/commands/renamenx
        �RENAMENXrrs   r�renamenxzBasicKeyCommands.renamenx�s���#�#�J��S�9�9�9rc���|||g}|r|�d��|r|�d��|�V|�d��	|�t|����n#t$rtd���wxYw|�V|�d��	|�t|����n#t$rtd���wxYw|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 check https://redis.io/commands/restore
        r��ABSTTLN�IDLETIMEzidletimemust be an integer�FREQzfrequency must be an integer�RESTORE)r,rrrr
)	rr��ttlr�r#�absttl�idletime�	frequencyrqs	         r�restorezBasicKeyCommands.restores,��:��U�#���	%��M�M�)�$�$�$��	$��M�M�(�#�#�#����M�M�*�%�%�%�
>��
�
�c�(�m�m�,�,�,�,���
>�
>�
>�� <�=�=�=�
>����� ��M�M�&�!�!�!�
@��
�
�c�)�n�n�-�-�-�-���
@�
@�
@�� >�?�?�?�
@����$�t�#�I�7��7�7�7�7s�"A/�/B	�$"C�C!c���||g}i}|��|�d��t|tj��r5|�t	|�������n:t|t��r|�|��nt
d���|��|�d��t|tj��r8|�t	|���dz����n:t|t��r|�|��nt
d���|	��|�d��t|	tj��rMt	|	jdz��}
t	tj	|	�
������|
z}	|�|	��|
��|�d	��t|
tj��rPt	|
jdz��}t	tj	|
�
������dz|z}
|�|
��|r|�d
��|r|�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 check 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��KEEPTTL�NX�XXr�TrU�SET)r,r+r�r�rr�rr�rar�r�r
)rr�r�r�r��nx�xx�keepttlrUr�r�rr�r�r�s               r�setzBasicKeyCommands.set6s���R������
�>��M�M�$�����"�h�0�1�1�
H��
�
�c�"�"2�"2�"4�"4�5�5�6�6�6�6��B��$�$�
H��
�
�b�!�!�!�!�� F�G�G�G�
�>��M�M�$�����"�h�0�1�1�
H��
�
�c�"�"2�"2�"4�"4�t�";�<�<�=�=�=�=��B��$�$�
H��
�
�b�!�!�!�!�� F�G�G�G����M�M�&�!�!�!��$�� 1�2�2�
>���(�7�2�3�3���4�;�t�~�~�'7�'7�8�8�9�9�A�=���M�M�$�������M�M�&�!�!�!��$�� 1�2�2�
F���)�D�0�1�1���4�;�t�~�~�'7�'7�8�8�9�9�D�@�2�E���M�M�$�����	%��M�M�)�$�$�$�
�	 ��M�M�$����
�	 ��M�M�$�����	"��M�M�%� � � �!�G�E�N�#�t�#�E�>�F�>�>�>�g�>�>�>rc�2�|�||��dSrY)r*r�s   r�__setitem__zBasicKeyCommands.__setitem__�s������u�����rc�>�|rdpd}|�d|||��S)z�
        Flag the ``offset`` in ``name`` as ``value``. Returns a boolean
        indicating the previous value of ``offset``.

        For more information check https://redis.io/commands/setbit
        rr�SETBITr�rr�rr�s    r�setbitzBasicKeyCommands.setbit�s,����!� �q���#�#�H�d�F�E�B�B�Brc��t|tj��rt|j����}|�d|||��S)z�
        Set the value of key ``name`` to ``value`` that expires in ``time``
        seconds. ``time`` can be represented by an integer or a Python
        timedelta object.

        For more information check https://redis.io/commands/setex
        �SETEXr�)rr�rar�s    r�setexzBasicKeyCommands.setex�sL���d�H�.�/�/�	-��)�t�)�+�+�,�,�D��#�#�G�T�4��?�?�?rc�0�|�d||��S)z�
        Set the value of key ``name`` to ``value`` if key doesn't exist

        For more information check https://redis.io/commands/setnx
        �SETNXrr�s   r�setnxzBasicKeyCommands.setnx�s���#�#�G�T�5�9�9�9rc�2�|�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 check https://redis.io/commands/setrange
        �SETRANGErr/s    r�setrangezBasicKeyCommands.setrange�s���#�#�J��f�e�D�D�Dr�stringsc	��dg}
||
vr'd�|
��}td|�����|dvrtd���|r|rtd���||���||g}|r|�d��|r|�d��	t	|��|�d	|g��n#t$rYnwxYw|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 check https://redis.io/commands/stralgo
        �LCSz, zThe supported algorithms are: )rHr:z-specific_argument can be only keys or stringsz(len and idx cannot be provided together.sLENsIDXsMINMATCHLENsWITHMATCHLEN�STRALGO)r��idx�minmatchlen�withmatchlen)r�r�upperr,rr}�	TypeErrorr
)
r�algo�value1�value2�specific_argumentr�r>r?r@r�supported_algo�supported_algos_strrs
             r�stralgozBasicKeyCommands.stralgo�s{��@ ����~�%�%�"&�)�)�N�";�";���R�=P�R�R�S�S�S��$7�7�7��K�L�L�L��	H�3�	H��F�G�G�G��)�/�/�1�1�6�6�B���	"��M�M�&�!�!�!��	"��M�M�&�!�!�!�	�������M�M�>�;�7�8�8�8�8���	�	�	��D�	�����	+��M�M�/�*�*�*�#�t�#��
�
�
�
���#�%�

�
��
�
�	
s�&C�
C�Cc�.�|�d|��S)z�
        Return the number of bytes stored in the value of ``name``

        For more information check https://redis.io/commands/strlen
        �STRLENrr�s  r�strlenzBasicKeyCommands.strlen�s���#�#�H�d�3�3�3r���c�2�|�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.
        �SUBSTRr�rr�rorps    r�substrzBasicKeyCommands.substrs��
�#�#�H�d�E�3�?�?�?rc��|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 check https://redis.io/commands/touch
        �TOUCHr�rr.s  r�touchzBasicKeyCommands.touch
s��$�t�#�G�3�d�3�3�3�3rc�.�|�d|��S)z�
        Returns the number of seconds until the key ``name`` will expire

        For more information check https://redis.io/commands/ttl
        �TTLrr�s  rrzBasicKeyCommands.ttlr�rc�.�|�d|��S)zu
        Returns the type of key ``name``

        For more information check https://redis.io/commands/type
        �TYPErr�s  r�typezBasicKeyCommands.typerrc�H�tjtd����dS)z�
        Watches the values at keys ``names``, or None if the key doesn't exist

        For more information check https://redis.io/commands/type
        z!Call WATCH from a Pipeline objectN��warnings�warn�DeprecationWarningr�s  r�watchzBasicKeyCommands.watch#s$��	�
�(�)L�M�M�N�N�N�N�Nrc�H�tjtd����dS)z�
        Unwatches the value at key ``name``, or None of the key doesn't exist

        For more information check https://redis.io/commands/unwatch
        z#Call UNWATCH from a Pipeline objectNr\rls r�unwatchzBasicKeyCommands.unwatch+s$��	�
�(�)N�O�O�P�P�P�P�Prc��|jdg|�R�S)z�
        Unlink one or more keys specified by ``names``

        For more information check https://redis.io/commands/unlink
        �UNLINKrr�s  r�unlinkzBasicKeyCommands.unlink3r�rrhrY�NF�r)NNNNF�r�rg)r�r�)FFNN)NNFFFFNN)r:FFNF)rM)=rZr[r\r]r,rrrvr{r�r"r��decrr�r�r�r��__contains__r�r�rUr�r�r�r�r�r�r��incrr�rHr�r�r�r�r�r�r�r�r�rrrrrrr!r*r,r0r3r6r9rIrLrQrUrrZr`rbrer^rrrjrj1s��������:�:�:�
9�
9�
9�
9�O�O�O�O�E�E�E�7�7�7�7�*5�5�5�5�(<�<�<�<��D�3�3�3����=�=�=�6�6�6��L�	:�	:�	:�	<�	<�	<�1�1�1�	4�	4�	4�9<�9<�9<�9<�v���<�<�<�A�A�A�
;�
;�
;�<�<�<�<��D�A�A�A�A�?�?�?�?�	6�	6�	6�	6�7�7�7�7�>�>�>�4�4�4�6�6�6�6�6�6�5�5�5�
;�
;�
;�=�=�=�
D�
D�
D�2�2�2�@�@�@�@�,;�;�;�8�8�8�:�:�:�����08�08�08�08�l������
�
�S?�S?�S?�S?�j���C�C�C�
@�
@�
@�:�:�:�
E�
E�
E�($�����>
�>
�>
�>
�@4�4�4�@�@�@�@�4�4�4�1�1�1�2�2�2�O�O�O�Q�Q�Q�6�6�6�6�6rrjc��eZdZdZdd�Zdd�Zdd�Zd�Zd�Zd�Z	dd
�Z
d�Zd�Zd
�Z
d�Zd�Zd�Zdd�Zd�Zd�Zd�Zdd�Z								dd�Zd	S)�ListCommandsz^
    Redis commands for List data type.
    see: https://redis.io/topics/data-types#lists
    rc�p�|�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 check https://redis.io/commands/blpop
        Nr�BLPOP�rr,r
�rrHr�s   r�blpopzListCommands.blpopB�J���?��G��D�$�'�'�����G����#�t�#�G�3�d�3�3�3�3rc�p�|�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 check https://redis.io/commands/brpop
        Nr�BRPOPrprqs   r�brpopzListCommands.brpopUrsrc�:�|�d}|�d|||��S)ae
        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 check https://redis.io/commands/brpoplpush
        Nr�
BRPOPLPUSHr)rr�rr�s    r�
brpoplpushzListCommands.brpoplpushhs(���?��G��#�#�L�#�s�G�D�D�Drc�0�|�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 check https://redis.io/commands/lindex
        �LINDEXr)rr�r
s   r�lindexzListCommands.lindexws���#�#�H�d�E�:�:�:rc�4�|�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 check https://redis.io/commands/linsert
        �LINSERTr)rr��where�refvaluer�s     r�linsertzListCommands.linsert�s ���#�#�I�t�U�H�e�L�L�Lrc�.�|�d|��S)z{
        Return the length of the list ``name``

        For more information check https://redis.io/commands/llen
        �LLENrr�s  r�llenzListCommands.llen�rrNc�`�|�|�d||��S|�d|��S)a|
        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 check https://redis.io/commands/lpop
        N�LPOPr�rr�r-s   r�lpopzListCommands.lpop��8�����'�'���e�<�<�<��'�'���5�5�5rc� �|jd|g|�R�S)z�
        Push ``values`` onto the head of the list ``name``

        For more information check https://redis.io/commands/lpush
        �LPUSHr�rr��valuess   r�lpushzListCommands.lpush��!��$�t�#�G�T�;�F�;�;�;�;rc� �|jd|g|�R�S)z�
        Push ``value`` onto the head of the list ``name`` if ``name`` exists

        For more information check https://redis.io/commands/lpushx
        �LPUSHXrr�s   r�lpushxzListCommands.lpushx�s!��$�t�#�H�d�<�V�<�<�<�<rc�2�|�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 check https://redis.io/commands/lrange
        �LRANGErrPs    r�lrangezListCommands.lrange�s���#�#�H�d�E�3�?�?�?rc�2�|�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 check https://redis.io/commands/lrem
        �LREMr)rr�r-r�s    r�lremzListCommands.lrem�s���#�#�F�D�%��?�?�?rc�2�|�d|||��S)z�
        Set ``position`` of list ``name`` to ``value``

        For more information check https://redis.io/commands/lset
        �LSETr)rr�r
r�s    r�lsetzListCommands.lset�s���#�#�F�D�%��?�?�?rc�2�|�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 check https://redis.io/commands/ltrim
        �LTRIMrrPs    r�ltrimzListCommands.ltrim�s���#�#�G�T�5�#�>�>�>rc�`�|�|�d||��S|�d|��S)au
        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 check https://redis.io/commands/rpop
        N�RPOPrr�s   r�rpopzListCommands.rpop�r�rc�0�|�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 check https://redis.io/commands/rpoplpush
        �	RPOPLPUSHrrs   r�	rpoplpushzListCommands.rpoplpush�s���#�#�K��c�:�:�:rc� �|jd|g|�R�S)z�
        Push ``values`` onto the tail of the list ``name``

        For more information check https://redis.io/commands/rpush
        �RPUSHrr�s   r�rpushzListCommands.rpush�r�rc�0�|�d||��S)z�
        Push ``value`` onto the tail of the list ``name`` if ``name`` exists

        For more information check https://redis.io/commands/rpushx
        �RPUSHXrr�s   r�rpushxzListCommands.rpushx����#�#�H�d�E�:�:�:rc��||g}|�|�d|g��|�|�d|g��|�|�d|g��|jdg|�R�S)ad
        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 check https://redis.io/commands/lpos
        N�RANK�COUNT�MAXLEN�LPOS�r}r
)rr�r��rankr-�maxlenrs       r�lposzListCommands.lposs~��4�������M�M�6�4�.�)�)�)����M�M�7�E�*�+�+�+����M�M�8�V�,�-�-�-�#�t�#�F�4�V�4�4�4�4rFc
��|�|�|�|�td���|g}
|�|
�d|g��|�|�|
�d||g��|�Pt|ttf��r|
�d|g��n|D]}|
�d|g���|r|
�d��|r|
�d��|�|
�d|g��|	r@|r/t|ttf��st
|��d	krtd
���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 check 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 keys�groups�SORT)rr}r+�bytesr{r,r�r
)
rr�rorV�byrU�desc�alpha�storer�r�gr�s
             r�sortzListCommands.sort1s���J
��#�+�3�?�u�}��J�K�K�K����
�>��M�M�5�"�+�&�&�&������M�M�8�U�C�0�1�1�1��?�
�#��s�|�,�,�
/��
�
�v�s�m�,�,�,�,��/�/�A��M�M�6�1�+�.�.�.�.��	#��M�M�'�"�"�"��	$��M�M�(�#�#�#����M�M�8�U�+�,�,�,��	��
�*�S�5�#�,�7�7�
�3�s�8�8�a�<�<��������9�S��X�X�X�T�:��#�t�#�F�?�V�?�?�?�w�?�?�?r�rrY�NNN)NNNNFFNF)rZr[r\r]rrrvryr|r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r^rrrmrm<s���������
4�4�4�4�&4�4�4�4�&
E�
E�
E�
E�	;�	;�	;�
M�
M�
M�2�2�2�
6�
6�
6�
6�<�<�<�=�=�=�
@�
@�
@�@�@�@�@�@�@�
?�
?�
?�
6�
6�
6�
6�;�;�;�<�<�<�;�;�;�$5�$5�$5�$5�R����
����F@�F@�F@�F@�F@�F@rrmc�`�eZdZdZdd�Zd
d�Zdd�Zdd�Zdd�Zdd	�Z	ddde
fd
�Zdde
fd�ZdS)�ScanCommandszF
    Redis SCAN commands.
    see: https://redis.io/commands/scan
    rNc��|g}|�|�d|g��|�|�d|g��|�|�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 check https://redis.io/commands/scan
        N�MATCH�COUNTrw�SCANr�)r�cursor�matchr-r�rrs       r�scanzScanCommands.scan�s���"������M�M�8�U�+�,�,�,����M�M�8�U�+�,�,�,����M�M�7�E�*�+�+�+�#�t�#�F�>�V�>�>�>�v�>�>�>rc+�dK�d}|dkr%|jd||||d�|��\}}|Ed{V��|dk�#dSdS)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�r-r�Nr^)r�)rr�r-r�rr��datas       r�	scan_iterzScanCommands.scan_iter�sn��������k�k�$�4�9���U�%�u���HN���L�F�D��O�O�O�O�O�O�O�	��k�k�k�k�k�krc��||g}|�|�d|g��|�|�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 check https://redis.io/commands/sscan
        Nr�r��SSCANr��rr�r�r�r-rs      r�sscanzScanCommands.sscan��b���������M�M�8�U�+�,�,�,����M�M�8�U�+�,�,�,�#�t�#�G�5�f�5�5�5�5rc#�rK�d}|dkr,|�||||���\}}|Ed{V��|dk�*dSdS)a
        Make an iterator using the SSCAN command so that the client doesn't
        need to remember the cursor position.

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

        ``count`` allows for hint the minimum number of returns
        r�r�r�r�r-N)r��rr�r�r-r�r�s      r�
sscan_iterzScanCommands.sscan_iter�sW��������k�k��:�:�d�6��e�:�T�T�L�F�D��O�O�O�O�O�O�O���k�k�k�k�k�krc��||g}|�|�d|g��|�|�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 check https://redis.io/commands/hscan
        Nr�r��HSCANr�r�s      r�hscanzScanCommands.hscan�r�rc#�K�d}|dkr>|�||||���\}}|���Ed{V��|dk�<dSdS)a
        Make an iterator using the HSCAN command so that the client doesn't
        need to remember the cursor position.

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

        ``count`` allows for hint the minimum number of returns
        r�rr�N)r�r�r�s      r�
hscan_iterzScanCommands.hscan_iter�sf��������k�k��:�:�d�6��e�:�T�T�L�F�D��z�z�|�|�#�#�#�#�#�#�#���k�k�k�k�k�krc��||g}|�|�d|g��|�|�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 check https://redis.io/commands/zscan
        Nr�r��score_cast_func�ZSCANr�)rr�r�r�r-r�rr�s        r�zscanzScanCommands.zscan�st���������M�M�8�U�+�,�,�,����M�M�8�U�+�,�,�,�$�o�6��#�t�#�G�@�f�@�@�@��@�@�@rc#�tK�d}|dkr-|�|||||���\}}|Ed{V��|dk�+dSdS)aL
        Make an iterator using the ZSCAN command so that the client doesn't
        need to remember the cursor position.

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

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

        ``score_cast_func`` a callable used to cast the score return value
        r�r)r�r�r-r�N)r�)rr�r�r-r�r�r�s       r�
zscan_iterzScanCommands.zscan_iter	sg��������k�k��:�:����� /�&���L�F�D��O�O�O�O�O�O�O���k�k�k�k�k�kr)rNNNr�)rNNrh)
rZr[r\r]r�r�r�r�r�r��floatr�r�r^rrr�r�zs���������
?�?�?�?�4����,6�6�6�6�$����6�6�6�6�$$�$�$�$�"#�$�d�E�A�A�A�A�*&*��u������rr�c�p�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
dd
�Zdd�Zd�Zd�Zd�ZdS)�SetCommandsz\
    Redis commands for Set data type.
    see: https://redis.io/topics/data-types#sets
    c� �|jd|g|�R�S)zu
        Add ``value(s)`` to set ``name``

        For more information check https://redis.io/commands/sadd
        �SADDrr�s   r�saddzSetCommands.sadd"	�!��$�t�#�F�D�:�6�:�:�:�:rc�.�|�d|��S)z�
        Return the number of elements in set ``name``

        For more information check https://redis.io/commands/scard
        �SCARDrr�s  r�scardzSetCommands.scard*	����#�#�G�T�2�2�2rc�>�t||��}|jdg|�R�S)z�
        Return the difference of sets specified by ``keys``

        For more information check https://redis.io/commands/sdiff
        �SDIFF�rr
�rrHr.s   r�sdiffzSetCommands.sdiff2	s.���D�$�'�'��#�t�#�G�3�d�3�3�3�3rc�@�t||��}|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 check https://redis.io/commands/sdiffstore
        �
SDIFFSTOREr��rrzrHr.s    r�
sdiffstorezSetCommands.sdiffstore;	s0���D�$�'�'��#�t�#�L�$�>��>�>�>�>rc�>�t||��}|jdg|�R�S)z�
        Return the intersection of sets specified by ``keys``

        For more information check https://redis.io/commands/sinter
        �SINTERr�r�s   r�sinterzSetCommands.sinterE	�.���D�$�'�'��#�t�#�H�4�t�4�4�4�4rc�@�t||��}|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 check https://redis.io/commands/sinterstore
        �SINTERSTOREr�r�s    r�sinterstorezSetCommands.sinterstoreN	�0���D�$�'�'��#�t�#�M�4�?�$�?�?�?�?rc�0�|�d||��S)z�
        Return a boolean indicating if ``value`` is a member of set ``name``

        For more information check https://redis.io/commands/sismember
        �	SISMEMBERrr�s   r�	sismemberzSetCommands.sismemberX	s���#�#�K��u�=�=�=rc�.�|�d|��S)z
        Return all members of the set ``name``

        For more information check https://redis.io/commands/smembers
        �SMEMBERSrr�s  r�smemberszSetCommands.smembers`	s���#�#�J��5�5�5rc�@�t||��}|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 check https://redis.io/commands/smismember
        �
SMISMEMBERr�)rr�r�r.s    r�
smismemberzSetCommands.smismemberh	s0���F�D�)�)��#�t�#�L�$�>��>�>�>�>rc�2�|�d|||��S)z�
        Move ``value`` from set ``src`` to set ``dst`` atomically

        For more information check https://redis.io/commands/smove
        �SMOVEr)rr�rr�s    r�smovezSetCommands.smover	s���#�#�G�S�#�u�=�=�=rNc�2�|dur|gpg}|jd|g|�R�S)z�
        Remove and return a random member of set ``name``

        For more information check https://redis.io/commands/spop
        N�SPOPr)rr�r-r.s    r�spopzSetCommands.spopz	s7���T�!�.��w�4�"��#�t�#�F�D�8�4�8�8�8�8rc�2�|dur|gpg}|jd|g|�R�S)aA
        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 check https://redis.io/commands/srandmember
        N�SRANDMEMBERr)rr��numberr.s    r�srandmemberzSetCommands.srandmember�	s7���d�"�0���6�B��#�t�#�M�4�?�$�?�?�?�?rc� �|jd|g|�R�S)zx
        Remove ``values`` from set ``name``

        For more information check https://redis.io/commands/srem
        �SREMrr�s   r�sremzSetCommands.srem�	r�rc�>�t||��}|jdg|�R�S)z�
        Return the union of sets specified by ``keys``

        For more information check https://redis.io/commands/sunion
        �SUNIONr�r�s   r�sunionzSetCommands.sunion�	r�rc�@�t||��}|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 check https://redis.io/commands/sunionstore
        �SUNIONSTOREr�r�s    r�sunionstorezSetCommands.sunionstore�	rrrY)rZr[r\r]r�r�r�r�r�rrrr
r
rrrrrr^rrr�r�	s��������
;�;�;�3�3�3�4�4�4�?�?�?�5�5�5�@�@�@�>�>�>�6�6�6�?�?�?�>�>�>�9�9�9�9�@�@�@�@�;�;�;�5�5�5�@�@�@�@�@rr�c���eZdZdZd�Z						dd�Z			d d	�Z					d!d
�Zd�Zd"d
�Z	d�Z
d�Zd�Zd�Z
d�Zd�Zd#d�Zd�Zd�Z					d$d�Zd%d�Zd&d�Z	d'd�Zd(d�Zd)d�ZdS)*�StreamCommandsz]
    Redis commands for Stream data type.
    see: https://redis.io/topics/streams-intro
    c�"�|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 check https://redis.io/commands/xack
        �XACKr)rr��	groupname�idss    r�xackzStreamCommands.xack�	s#��$�t�#�F�D�)�B�c�B�B�B�Brr�NTFc	��g}	|�|�td���|�xt|t��r|dkrtd���|	�d��|r|	�d��|	�t	|����|�A|	�d��|r|	�d��|	�|��|�|	�d|g��|r|	�d	��|	�|��t|t��rt|��d
krtd���|���D]}
|	�|
���|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 check https://redis.io/commands/xadd
        Nz8Only one of ```maxlen``` or ```minid``` may be specifiedrz&XADD maxlen must be a positive integer�MAXLEN�~�MINIDr�s
NOMKSTREAMrz$XADD fields must be a non-empty dict�XADD)
rr+rr,r{r}�dictr�r�r
)rr��fields�idr��approximate�
nomkstream�minid�limitrr�s           r�xaddzStreamCommands.xadd�	s���4����%�"3��M���
����f�c�*�*�
J�f�q�j�j�� H�I�I�I��M�M�)�$�$�$��
$��
�
�d�#�#�#��M�M�#�f�+�+�&�&�&����M�M�(�#�#�#��
$��
�
�d�#�#�#��M�M�%� � � ����M�M�8�U�+�,�,�,��	)��M�M�-�(�(�(��
�
�b�����&�$�'�'�	D�3�v�;�;�!�+;�+;��B�C�C�C��L�L�N�N�	 �	 �D��M�M�$�����#�t�#�F�D�:�6�:�:�:�:rrc�l�	t|��dkrtd���n#t$rYnwxYwi}|||||g}		t|��dkrtd���|	�d|g��n#t$rYnwxYw|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 check https://redis.io/commands/xautoclaim
        rz6XAUTOCLAIM min_idle_time must be a nonnegative integer�%XPENDING count must be a integer >= 0r��JUSTIDT�parse_justid�
XAUTOCLAIM)rrrBr}r,r
)
rr�r"�consumername�
min_idle_time�start_idr-�justidrrs
          r�
xautoclaimzStreamCommands.xautoclaim�	s��8	��=�!�!�A�%�%��O����&���	�	�	��D�	�������	�<���I��	��5�z�z�A�~�~�� G�H�H�H��M�M�8�U�+�,�,�,�,���	�	�	��D�	�����	*��M�M�)�$�$�$�%)�F�>�"�#�t�#�L�D�6�D�D�D�V�D�D�Ds�"%�
2�2�9A9�9
B�Bc���t|t��r|dkrtd���t|ttf��r|std���i}|||t|��g}|�t|����|�Ht|t��std���|�dt|��f��|�Ht|t��std���|�dt|��f��|�Ht|t��std	���|�d
t|��f��|	r9t|	t��std���|�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 check 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 booleanr4Tr5�XCLAIM)
r+rrr��tupler{r}r~r,r
)
rr�r"r7r8�message_ids�idlera�
retrycountr<r:rrs
             r�xclaimzStreamCommands.xclaim'
s��J�-��-�-�	V���1B�1B��T�U�U�U��+��e�}�5�5�	�[�	��0���
�
���	�<��]�1C�1C�D���
�
�d�;�'�'�(�(�(����d�C�(�(�
B�� @�A�A�A��M�M�7�C��I�I�.�/�/�/����d�C�(�(�
B�� @�A�A�A��M�M�7�C��I�I�.�/�/�/��!��j�#�.�.�
H�� F�G�G�G��M�M�=�#�j�/�/�:�;�;�;��	$��e�T�*�*�
B�� @�A�A�A��M�M�(�#�#�#��	*��f�d�+�+�
C�� A�B�B�B��M�M�)�$�$�$�%)�F�>�"�#�t�#�H�@�v�@�@�@��@�@�@rc� �|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 check https://redis.io/commands/xdel
        �XDELr)rr�r#s   r�xdelzStreamCommands.xdelp
s!��$�t�#�F�D�7�3�7�7�7�7r�$c�P�d|||g}|r|�d��|j|�S)a1
        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 check https://redis.io/commands/xgroup-create
        z
XGROUP CREATEsMKSTREAMrg)rr�r"r,�mkstreamrs      r�
xgroup_createzStreamCommands.xgroup_createz
s<��"�4��B�7���	'��M�M�+�&�&�&�#�t�#�V�,�,rc�2�|�d|||��S)az
        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 check https://redis.io/commands/xgroup-delconsumer
        zXGROUP DELCONSUMERr�rr�r"r7s    r�xgroup_delconsumerz!StreamCommands.xgroup_delconsumer�
s���#�#�$8�$�	�<�X�X�Xrc�0�|�d||��S)z�
        Destroy a consumer group.
        name: name of the stream.
        groupname: name of the consumer group.

        For more information check https://redis.io/commands/xgroup-destroy
        zXGROUP DESTROYr�rr�r"s   r�xgroup_destroyzStreamCommands.xgroup_destroy�
s���#�#�$4�d�I�F�F�Frc�2�|�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rKs    r�xgroup_createconsumerz$StreamCommands.xgroup_createconsumer�
s%���#�#�#�T�9�l�
�
�	
rc�2�|�d|||��S)a6
        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 check https://redis.io/commands/xgroup-setid
        zXGROUP SETIDr)rr�r"r,s    r�xgroup_setidzStreamCommands.xgroup_setid�
s���#�#�N�D�)�R�H�H�Hrc�0�|�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 check https://redis.io/commands/xinfo-consumers
        zXINFO CONSUMERSrrNs   r�xinfo_consumerszStreamCommands.xinfo_consumers�
s���#�#�$5�t�Y�G�G�Grc�.�|�d|��S)z�
        Returns general information about the consumer groups of the stream.
        name: name of the stream.

        For more information check https://redis.io/commands/xinfo-groups
        zXINFO GROUPSrr�s  r�xinfo_groupszStreamCommands.xinfo_groups�
s���#�#�N�D�9�9�9rc�d�|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 check https://redis.io/commands/xinfo-stream
        sFULL�fullzXINFO STREAMrg)rr�rYrr�s     r�xinfo_streamzStreamCommands.xinfo_stream�
sV��������	%��M�M�'�"�"�"��t�n�G�#�t�#�N�G�V�G�G�G�w�G�G�Grc�.�|�d|��S)z�
        Returns the number of elements in a given stream.

        For more information check https://redis.io/commands/xlen
        �XLENrr�s  r�xlenzStreamCommands.xlen�
rrc�0�|�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 check https://redis.io/commands/xpending
        �XPENDINGrrNs   r�xpendingzStreamCommands.xpending�
s���#�#�J��i�@�@�@rc��|||hdhkr)|�|�td���|�||��S||g}|�|�|�td���	t|��dkrtd���|�d|g��n#t$rYnwxYw	t|��dkrtd���|�|||g��n#t$rYnwxYw|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 >= 0�IDLEr3r_�parse_detailT)rr`rr}rBr,r
)	rr�r"r@�min�maxr-r7rs	         r�xpending_rangezStreamCommands.xpending_range�
sx��,
��e����&�&���<�#;��:����
�=�=��y�1�1�1��	�"���;�#�+����9���
�
	��4�y�y�1�}�}�� F�G�G�G��M�M�6�4�.�)�)�)�)���	�	�	��D�	����	��5�z�z�A�~�~�� G�H�H�H��M�M�3��U�+�,�,�,�,���	�	�	��D�	�����	(��M�M�,�'�'�'�#�t�#�J�K��K�K�K�d�K�K�Ks$�9B�
B�B�:C�
C!� C!�-�+c���||g}|�at|t��r|dkrtd���|�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 check https://redis.io/commands/xrange
        Nrz'XRANGE count must be a positive integerr��XRANGE�r+rrr,r{r
)rr�rdrer-rs      r�xrangezStreamCommands.xrange&s����s������e�S�)�)�
K�U�Q�Y�Y�� I�J�J�J��M�M�(�#�#�#��M�M�#�e�*�*�%�%�%�#�t�#�H�d�<�V�<�<�<�<rc���g}|�at|t��r|dkrtd���|�d��|�t	|����|�at|t��r|dkrtd���|�d��|�t	|����t|t
��rt
|��dkrtd���|�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 check https://redis.io/commands/xread
        Nrz*XREAD block must be a non-negative integer�BLOCKrz&XREAD count must be a positive integerr�z&XREAD streams must be a non empty dict�STREAMS�XREAD)r+rrr,r{r*r��zipr�r}r
)r�streamsr-�blockrrHr�s       r�xreadzStreamCommands.xread<sV�������e�S�)�)�
N�U�Q�Y�Y�� L�M�M�M��M�M�(�#�#�#��M�M�#�e�*�*�%�%�%����e�S�)�)�
J�U�Q�Y�Y�� H�I�I�I��M�M�(�#�#�#��M�M�#�e�*�*�%�%�%��'�4�(�(�	F�C��L�L�A�,=�,=��D�E�E�E��
�
�j�!�!�!��G�M�M�O�O�,���f��
�
�d�����
�
�f����#�t�#�G�5�f�5�5�5�5rc��d||g}|�at|t��r|dkrtd���|�d��|�t	|����|�at|t��r|dkrtd���|�d��|�t	|����|r|�d	��t|t
��rt
|��dkrtd
���|�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 check https://redis.io/commands/xreadgroup
        sGROUPNrz+XREADGROUP count must be a positive integerr�rz/XREADGROUP block must be a non-negative integerrnsNOACKz+XREADGROUP streams must be a non empty dictro�
XREADGROUP)r+rrr,r{r*r�r}rHr�r
)rr"r7rrr-rs�noackrs        r�
xreadgroupzStreamCommands.xreadgroupZss�� �I�|�4�����e�S�)�)�
O�U�Q�Y�Y�� M�N�N�N��M�M�(�#�#�#��M�M�#�e�*�*�%�%�%����e�S�)�)�
V�U�Q�Y�Y�� T�U�U�U��M�M�(�#�#�#��M�M�#�e�*�*�%�%�%��	$��M�M�(�#�#�#��'�4�(�(�	K�C��L�L�A�,=�,=��I�J�J�J��
�
�j�!�!�!��
�
�g�l�l�n�n�%�%�%��
�
�g�n�n�&�&�'�'�'�#�t�#�L�:�6�:�:�:�:rc���||g}|�at|t��r|dkrtd���|�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 check https://redis.io/commands/xrevrange
        Nrz*XREVRANGE count must be a positive integerr��	XREVRANGErk)rr�rerdr-rs      r�	xrevrangezStreamCommands.xrevrange~s����s������e�S�)�)�
N�U�Q�Y�Y�� L�M�M�M��M�M�(�#�#�#��M�M�#�e�*�*�%�%�%�#�t�#�K��?��?�?�?�?rc��g}|�|�td���|�|�d��|�|�d��|r|�d��|�|�|��|�|�|��|�*|�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 check https://redis.io/commands/xtrim
        Nz4Only one of ``maxlen`` or ``minid`` may be specifiedr&r(r'r��XTRIMr~)rr�r�r-r/r0rs       r�xtrimzStreamCommands.xtrim�s�������%�"3��U�V�V�V����M�M�)�$�$�$����M�M�(�#�#�#��	 ��M�M�$�������M�M�&�!�!�!����M�M�%� � � ����M�M�(�#�#�#��M�M�%� � � �#�t�#�G�T�;�F�;�;�;�;r)r�NTFNN)rNF)NNNFF)rFFrf)NNNNN)rgrhNrh)NNF)rhrgN)NTNN)rZr[r\r]r$r1r;rBrErIrLrOrQrSrUrWrZr]r`rfrlrtrxr{r~r^rrrr�	s��������
	C�	C�	C�������5;�5;�5;�5;�z���1E�1E�1E�1E�t�
����GA�GA�GA�GA�R8�8�8�-�-�-�-�Y�Y�Y�G�G�G�

�

�

�	I�	I�	I�H�H�H�:�:�:�
H�
H�
H�
H�2�2�2�A�A�A������7L�7L�7L�7L�r=�=�=�=�,6�6�6�6�>OT�";�";�";�";�H@�@�@�@�,<�<�<�<�<�<rrc�<�eZdZdZ	d&d�Zd�Zd�Zd'd�Zd�Zd	�Z	d(d
�Z
d)d�Zd�Zd)d
�Z
d)d�Zd(d�Zd*d�Zd*d�Zddddeddfd�Zddeddddfd�Zdefd�Z					d+d�Zd,d�Zd,d�Zdddefd�Zdddefd�Zd�Zd�Zd�Zd�Zd�Zd �Z d!�Z!d(d"�Z"d)d#�Z#d$�Z$d)d%�Z%dS)-�SortedSetCommandszw
    Redis commands for Sorted Sets data type.
    see: https://redis.io/topics/data-types-intro#redis-sorted-sets
    FNc	��|std���|r|rtd���|r"t|��dkrtd���|dur|�|�td���g}	i}
|r|	�d��|r|	�d	��|r|	�d
��|r|	�d��d|
d<|r|	�d
��|r|	�d��|���D]8}|	�|d��|	�|d���9|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 bothrzFZADD option 'incr' only works when passing a single element/score pairTNz/Only one of 'nx', 'lt', or 'gr' may be defined.sNXsXXsCHsINCR�as_scoresGTsLTr�ZADD)rr�r,r�r
)rr�r�r'r(�chrk�gt�ltrr�r�s            r�zaddzSortedSetCommands.zadd�s���H�	M��K�L�L�L�
�	I�"�	I��G�H�H�H��	�C��L�L�A�%�%��,���
���:�:�2�>�R�^��M�N�N�N�����
�	!��M�M�%� � � �
�	!��M�M�%� � � �
�	!��M�M�%� � � ��	'��M�M�'�"�"�"�"&�G�J��
�	!��M�M�%� � � �
�	!��M�M�%� � � ��M�M�O�O�	#�	#�D��M�M�$�q�'�"�"�"��M�M�$�q�'�"�"�"�"�#�t�#�F�D�E�6�E�E�E�W�E�E�Erc�.�|�d|��S)z�
        Return the number of elements in the sorted set ``name``

        For more information check https://redis.io/commands/zcard
        �ZCARDrr�s  r�zcardzSortedSetCommands.zcardr�rc�2�|�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 check https://redis.io/commands/zcount
        �ZCOUNTr�rr�rdres    r�zcountzSortedSetCommands.zcounts���#�#�H�d�C��=�=�=rc�p�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 check https://redis.io/commands/zdiff
        �
WITHSCORES�ZDIFF)r�r,r
)rrH�
withscoresrs    r�zdiffzSortedSetCommands.zdiffsL���d�)�)�#�d�#���	(��M�M�,�'�'�'�#�t�#�G�5�f�5�5�5�5rc�D�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 check https://redis.io/commands/zdiffstore
        �
ZDIFFSTORE)r�r
)rrzrHrs    r�
zdiffstorezSortedSetCommands.zdiffstores4���d�)�)�#�d�#��#�t�#�L�$�@��@�@�@�@rc�2�|�d|||��S)z�
        Increment the score of ``value`` in sorted set ``name`` by ``amount``

        For more information check https://redis.io/commands/zincrby
        �ZINCRBYr)rr�r�r�s    r�zincrbyzSortedSetCommands.zincrby's���#�#�I�t�V�U�C�C�Crc�6�|�dd|||���S)a3
        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 check https://redis.io/commands/zinter
        �ZINTERN�r���_zaggregate�rrH�	aggregater�s    r�zinterzSortedSetCommands.zinter/s#������$��i�J��W�W�Wrc�2�|�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 check https://redis.io/commands/zinterstore
        �ZINTERSTOREr��rrzrHr�s    r�zinterstorezSortedSetCommands.zinterstore=s�����
�t�T�9�E�E�Erc�2�|�d|||��S)z�
        Return the number of items in the sorted set ``name`` between the
        lexicographical range ``min`` and ``max``.

        For more information check https://redis.io/commands/zlexcount
        �	ZLEXCOUNTrr�s    r�	zlexcountzSortedSetCommands.zlexcountKs���#�#�K��s�C�@�@�@rc�@�|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 check https://redis.io/commands/zpopmax
        Nr�T�ZPOPMAXr�rr�r-r.r�s     r�zpopmaxzSortedSetCommands.zpopmaxT�I���T�!�.��w�4�"����&��#�t�#�I�t�F�d�F�F�F�g�F�F�Frc�@�|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 check https://redis.io/commands/zpopmin
        Nr�T�ZPOPMINrr�s     r�zpopminzSortedSetCommands.zpopmin_r�rc��g}|�|�|��|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 check https://redis.io/commands/zrandmember
        Nr��ZRANDMEMBERrg)rrQr-r�rqs     r�zrandmemberzSortedSetCommands.zrandmemberjsX�� �����M�M�%� � � ��	(��M�M�,�'�'�'�#�t�#�M�3�@��@�@�@�@rrc�p�|�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 check https://redis.io/commands/bzpopmax
        Nr�BZPOPMAXrprqs   r�bzpopmaxzSortedSetCommands.bzpopmax��J���?��G��D�$�'�'�����G����#�t�#�J�6��6�6�6�6rc�p�|�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 check https://redis.io/commands/bzpopmin
        Nr�BZPOPMINrprqs   r�bzpopminzSortedSetCommands.bzpopmin�r�rc
���|r|rtd���|�|�|�|�td���|r|	rtd���|g}
|r|
�|��|
�|||g��|r|
�d��|r|
�d��|r|
�d��|�|�|
�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``.�BYSCORE�BYLEX�REV�LIMITr��r�r�)rr,r}r
)rr�rzr�rorpr��byscore�bylexr�r�rrVrr�s               r�_zrangezSortedSetCommands._zrange�s[���	�u�	��M���
�
��3�;�C�O����L�M�M�M��	�Z�	��P���
�����	 ��M�M�$�����
�
�t�U�C�(�)�)�)��	%��M�M�)�$�$�$��	#��M�M�'�"�"�"��	!��M�M�%� � � ���#�/��M�M�7�F�C�0�1�1�1��	(��M�M�,�'�'�'�!+��P�P��#�t�#�V�7�w�7�7�7rc��|s!|s|	�|
�|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 check https://redis.io/commands/zrange
        N�ZRANGE)�	zrevranger�)rr�rorpr�r�r�r�r�rrVs           r�zrangezSortedSetCommands.zrange�sv��V�	Q�u�	Q�&�.�S�[�d�[��>�>�$��s�J��P�P�P��|�|�������������

�

�
	
rc�`�d|||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 check https://redis.io/commands/zrevrange
        �	ZREVRANGE�
WITHSCORESr�rg)rr�rorpr�r�rr�s        rr�zSortedSetCommands.zrevrange
sQ���t�U�C�0���	)��M�M�-�(�(�(�!+��P�P��#�t�#�V�7�w�7�7�7rc
�B�|�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 check https://redis.io/commands/zrangestore
        �ZRANGESTOREFN)r�)
rrzr�rorpr�r�r�rrVs
          r�zrangestorezSortedSetCommands.zrangestore#
s?��F�|�|�������������

�

�
	
rc��|�|�|�|�td���d|||g}|�|�|�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 check https://redis.io/commands/zrangebylex
        Nr��ZRANGEBYLEXr��rr}r
)rr�rdrerorVrs       r�zrangebylexzSortedSetCommands.zrangebylexU
sf��
��#�+�3�?�u�}��J�K�K�K���s�C�0�������M�M�8�U�C�0�1�1�1�#�t�#�V�,�,rc��|�|�|�|�td���d|||g}|�|�|�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 check https://redis.io/commands/zrevrangebylex
        Nr��ZREVRANGEBYLEXr�r�)rr�rerdrorVrs       r�zrevrangebylexz SortedSetCommands.zrevrangebylexf
sf��
��#�+�3�?�u�}��J�K�K�K�"�D�#�s�3�������M�M�7�E�3�/�0�0�0�#�t�#�V�,�,rc���|�|�|�|�td���d|||g}|�|�|�d||g��|r|�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 check https://redis.io/commands/zrangebyscore
        Nr��
ZRANGEBYSCOREr�r�r��rr}r,r
)
rr�rdrerorVr�r�rr�s
          r�
zrangebyscorezSortedSetCommands.zrangebyscorew
s���0
��#�+�3�?�u�}��J�K�K�K�!�4��c�2�������M�M�7�E�3�/�0�0�0��	(��M�M�,�'�'�'�!+��P�P��#�t�#�V�7�w�7�7�7rc���|�|�|�|�td���d|||g}|�|�|�d||g��|r|�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 check https://redis.io/commands/zrevrangebyscore
        Nr��ZREVRANGEBYSCOREr�r�r�r�)
rr�rerdrorVr�r�rr�s
          r�zrevrangebyscorez"SortedSetCommands.zrevrangebyscore�
s���0
��#�+�3�?�u�}��J�K�K�K�$�d�C��5�������M�M�7�E�3�/�0�0�0��	(��M�M�,�'�'�'�!+��P�P��#�t�#�V�7�w�7�7�7rc�0�|�d||��S)z�
        Returns a 0-based value indicating the rank of ``value`` in sorted set
        ``name``

        For more information check https://redis.io/commands/zrank
        �ZRANKrr�s   r�zrankzSortedSetCommands.zrank�
s���#�#�G�T�5�9�9�9rc� �|jd|g|�R�S)z�
        Remove member ``values`` from sorted set ``name``

        For more information check https://redis.io/commands/zrem
        �ZREMrr�s   r�zremzSortedSetCommands.zrem�
r�rc�2�|�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 check https://redis.io/commands/zremrangebylex
        �ZREMRANGEBYLEXrr�s    r�zremrangebylexz SortedSetCommands.zremrangebylex�
s���#�#�$4�d�C��E�E�Erc�2�|�d|||��S)ag
        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 check https://redis.io/commands/zremrangebyrank
        �ZREMRANGEBYRANKrr�s    r�zremrangebyrankz!SortedSetCommands.zremrangebyrank�
s���#�#�$5�t�S�#�F�F�Frc�2�|�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 check https://redis.io/commands/zremrangebyscore
        �ZREMRANGEBYSCORErr�s    r�zremrangebyscorez"SortedSetCommands.zremrangebyscore�
s���#�#�$6��c�3�G�G�Grc�0�|�d||��S)z�
        Returns a 0-based value indicating the descending rank of
        ``value`` in sorted set ``name``

        For more information check https://redis.io/commands/zrevrank
        �ZREVRANKrr�s   r�zrevrankzSortedSetCommands.zrevrank�
s���#�#�J��e�<�<�<rc�0�|�d||��S)z�
        Return the score of element ``value`` in sorted set ``name``

        For more information check https://redis.io/commands/zscore
        �ZSCORErr�s   r�zscorezSortedSetCommands.zscore�
r�rc�6�|�dd|||���S)aB
        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 check https://redis.io/commands/zunion
        �ZUNIONNr�r�r�s    r�zunionzSortedSetCommands.zunion�
s#������$��i�J��W�W�Wrc�2�|�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 check https://redis.io/commands/zunionstore
        �ZUNIONSTOREr�r�s    r�zunionstorezSortedSetCommands.zunionstores�����
�t�T�9�E�E�Erc�L�|std���|g|z}|jdg|�R�S)a{
        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 check https://redis.io/commands/zmscore
        z(ZMSCORE members must be a non-empty list�ZMSCOREr�)rrQ�membersrs    r�zmscorezSortedSetCommands.zmscoresB���	H��F�G�G�G������#�t�#�I�7��7�7�7�7rc��|g}|�|�|��|�t|����t|t��r)|���|���}}nd}|�|��|r*|�d��|�|��|rP|���dvr+|�d��|�|��ntd���|�	dd��r|�d��|j
|i|��S)NsWEIGHTS)�SUM�MIN�MAXs	AGGREGATEz!aggregate can be sum, min or max.r�Fr�)r,r�r+r*rHr�r}rArrUr
)rr�rzrHr�r�r�weightss        rr�zSortedSetCommands._zaggregate!s>��������M�M�$�����
�
�c�$�i�i� � � ��d�D�!�!�	� �I�I�K�K������'�D�D��G��
�
�d�����	#��M�M�*�%�%�%��M�M�'�"�"�"��	E���� � �$9�9�9��
�
�l�+�+�+��
�
�i�(�(�(�(�� C�D�D�D��;�;�|�U�+�+�	)��M�M�-�(�(�(�#�t�#�V�7�w�7�7�7r)FFFFNNrfrfrYr�)FFFNNrh)&rZr[r\r]r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r^rrr�r��s��������TX�BF�BF�BF�BF�H3�3�3�>�>�>�
6�
6�
6�
6�A�A�A�D�D�D�X�X�X�X�F�F�F�F�A�A�A�	G�	G�	G�	G�	G�	G�	G�	G�A�A�A�A�07�7�7�7�&7�7�7�7�4�������(8�(8�(8�(8�^�������;
�;
�;
�;
�z6;�E�8�8�8�8�4��
���0
�0
�0
�0
�d-�-�-�-�"-�-�-�-�,���� 8� 8� 8� 8�N���� 8� 8� 8� 8�D:�:�:�;�;�;�	F�	F�	F�	G�	G�	G�H�H�H�=�=�=�;�;�;�	X�	X�	X�	X�F�F�F�F�8�8�8� 8�8�8�8�8�8rr�c�$�eZdZdZd�Zd�Zd�ZdS)�HyperlogCommandszr
    Redis commands of HyperLogLogs data type.
    see: https://redis.io/topics/data-types-intro#hyperloglogs
    c� �|jd|g|�R�S)z�
        Adds the specified elements to the specified HyperLogLog.

        For more information check https://redis.io/commands/pfadd
        �PFADDrr�s   r�pfaddzHyperlogCommands.pfadd?r�rc��|jdg|�R�S)z�
        Return the approximated cardinality of
        the set observed by the HyperLogLog at key(s).

        For more information check https://redis.io/commands/pfcount
        �PFCOUNTr)r�sourcess  r�pfcountzHyperlogCommands.pfcountGs��$�t�#�I�8��8�8�8�8rc� �|jd|g|�R�S)z�
        Merge N different HyperLogLogs into a single one.

        For more information check https://redis.io/commands/pfmerge
        �PFMERGEr)rrzrs   r�pfmergezHyperlogCommands.pfmergePs!��$�t�#�I�t�>�g�>�>�>�>rN)rZr[r\r]rrrr^rrrr9sK��������
<�<�<�9�9�9�?�?�?�?�?rrc�l�eZdZdZd�Zd�Zd�Zd�Zdd�Zdd	�Z	d
�Z
d�Zdd
�Zd�Z
d�Zd�Zd�Zd�ZdS)�HashCommandszk
    Redis commands for Hash data type.
    see: https://redis.io/topics/data-types-intro#redis-hashes
    c� �|jd|g|�R�S)zw
        Delete ``keys`` from hash ``name``

        For more information check https://redis.io/commands/hdel
        �HDELr)rr�rHs   r�hdelzHashCommands.hdel_s!��$�t�#�F�D�8�4�8�8�8�8rc�0�|�d||��S)z�
        Returns a boolean indicating if ``key`` exists within hash ``name``

        For more information check https://redis.io/commands/hexists
        �HEXISTSr�rr�rQs   r�hexistszHashCommands.hexistsgs���#�#�I�t�S�9�9�9rc�0�|�d||��S)z�
        Return the value of ``key`` within the hash ``name``

        For more information check https://redis.io/commands/hget
        �HGETrrs   r�hgetzHashCommands.hgetos���#�#�F�D�#�6�6�6rc�.�|�d|��S)z�
        Return a Python dict of the hash's name/value pairs

        For more information check https://redis.io/commands/hgetall
        �HGETALLrr�s  r�hgetallzHashCommands.hgetallwr�rrc�2�|�d|||��S)z�
        Increment the value of ``key`` in hash ``name`` by ``amount``

        For more information check https://redis.io/commands/hincrby
        �HINCRBYr�rr�rQr�s    r�hincrbyzHashCommands.hincrbys���#�#�I�t�S�&�A�A�Arr�c�2�|�d|||��S)z�
        Increment the value of ``key`` in hash ``name`` by floating ``amount``

        For more information check https://redis.io/commands/hincrbyfloat
        �HINCRBYFLOATrrs    r�hincrbyfloatzHashCommands.hincrbyfloat�s���#�#�N�D�#�v�F�F�Frc�.�|�d|��S)z�
        Return the list of keys within hash ``name``

        For more information check https://redis.io/commands/hkeys
        �HKEYSrr�s  r�hkeyszHashCommands.hkeys�r�rc�.�|�d|��S)z�
        Return the number of elements in hash ``name``

        For more information check https://redis.io/commands/hlen
        �HLENrr�s  r�hlenzHashCommands.hlen�rrNc���|�|std���g}|�|�||f��|r,|���D]}|�|���|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``.
        Returns the number of fields that were added.

        For more information check https://redis.io/commands/hset
        Nz'hset' with no key value pairs�HSET)rr}r�r
)rr�rQr�r�r�r�s       r�hsetzHashCommands.hset�s����;�w�;��<�=�=�=����?��L�L�#�u��&�&�&��	#��
�
���
#�
#�����T�"�"�"�"�#�t�#�F�D�9�5�9�9�9�9rc�2�|�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 check https://redis.io/commands/hsetnx
        �HSETNXr)rr�rQr�s    r�hsetnxzHashCommands.hsetnx�s���#�#�H�d�C��?�?�?rc�
�tj|jj�d|jj�d�td���|std���g}|���D]}|�|���|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 check https://redis.io/commands/hmset
        z.hmset() is deprecated. Use z.hset() instead.r�)�
stacklevelz"'hmset' with 'mapping' of length 0�HMSET)	r]r^�	__class__rZr_rr�r}r
)rr�r�r�r�s     r�hmsetzHashCommands.hmset�s���	�
��~�&�
=�
=��>�*�
=�
=�
=���		
�	
�	
�	
��	B��@�A�A�A����M�M�O�O�	�	�D��L�L������#�t�#�G�T�:�E�:�:�:�:rc�@�t||��}|jd|g|�R�S)z�
        Returns a list of values ordered identically to ``keys``

        For more information check https://redis.io/commands/hmget
        �HMGETr�)rr�rHr.s    r�hmgetzHashCommands.hmget�s0���D�$�'�'��#�t�#�G�T�9�D�9�9�9�9rc�.�|�d|��S)z�
        Return the list of values within hash ``name``

        For more information check https://redis.io/commands/hvals
        �HVALSrr�s  r�hvalszHashCommands.hvals�r�rc�0�|�d||��S)z�
        Return the number of bytes stored in the value of ``key``
        within hash ``name``

        For more information check https://redis.io/commands/hstrlen
        �HSTRLENrrs   r�hstrlenzHashCommands.hstrlen�s���#�#�I�t�S�9�9�9rrgrhr�)rZr[r\r]rrrrrr!r$r'r*r-r2r5r8r;r^rrr
r
Ys
��������
9�9�9�:�:�:�7�7�7�5�5�5�B�B�B�B�G�G�G�G�3�3�3�2�2�2�:�:�:�:�(@�@�@�;�;�;�(:�:�:�3�3�3�:�:�:�:�:rr
c�,�eZdZdZd�Zdd�Zd�Zd�ZdS)	�PubSubCommandszG
    Redis PubSub commands.
    see https://redis.io/topics/pubsub
    c�"�|jd||fi|��S)z�
        Publish ``message`` on ``channel``.
        Returns the number of subscribers the message was delivered to.

        For more information check https://redis.io/commands/publish
        �PUBLISHr)r�channel�messagers    r�publishzPubSubCommands.publish�s#��$�t�#�I�w��J�J�6�J�J�Jrr�c� �|jd|fi|��S)z�
        Return a list of channels that have at least one subscriber

        For more information check https://redis.io/commands/pubsub-channels
        zPUBSUB CHANNELSrr�s   r�pubsub_channelszPubSubCommands.pubsub_channels�s"��$�t�#�$5�w�I�I�&�I�I�Irc��|jdi|��S)z�
        Returns the number of subscriptions to patterns

        For more information check https://redis.io/commands/pubsub-numpat
        �
PUBSUB NUMPAT)rFrr#s  r�
pubsub_numpatzPubSubCommands.pubsub_numpatr^rc�$�|jdg|�Ri|��S)z�
        Return a list of (channel, number of subscribers) tuples
        for each channel given in ``*args``

        For more information check https://redis.io/commands/pubsub-numsub
        z
PUBSUB NUMSUBrrDs   r�
pubsub_numsubzPubSubCommands.pubsub_numsub
s'��$�t�#�O�E�d�E�E�E�f�E�E�ErNrg)rZr[r\r]rBrDrGrIr^rrr=r=�sk��������
K�K�K�J�J�J�J�?�?�?�F�F�F�F�Frr=c�D�eZdZdZd�Zd�Zd�Zd�Zdd�Zd�Z	d	�Z
d
�ZdS)�ScriptCommandsz|
    Redis Lua script commands. see:
    https://redis.com/ebook/part-3-next-steps/chapter-11-scripting-redis-with-lua/
    c�"�|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 check  https://redis.io/commands/eval
        �EVALr)r�script�numkeys�
keys_and_argss    r�evalzScriptCommands.evals#��$�t�#�F�F�G�L�m�L�L�L�Lrc�"�|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 check  https://redis.io/commands/evalsha
        �EVALSHAr)r�sharOrPs    r�evalshazScriptCommands.evalsha's#��$�t�#�I�s�G�L�m�L�L�L�Lrc��|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 check  https://redis.io/commands/script-exists
        z
SCRIPT EXISTSrrTs  r�
script_existszScriptCommands.script_exists5s��$�t�#�O�;�d�;�;�;�;rc� �td���)Nz<SCRIPT DEBUG is intentionally not implemented in the client.r�rTs  r�script_debugzScriptCommands.script_debug?r�rNc�T�|dvrtd���|�g}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 check  https://redis.io/commands/script-flush
        )r��ASYNCNzpSCRIPT FLUSH defaults to SYNC in redis > 6.2, or accepts SYNC/ASYNC. For older versions, of redis leave as None.NzSCRIPT FLUSHr�)r�	sync_typers   r�script_flushzScriptCommands.script_flushDsX���3�3�3��*���
�
���F�F��[�F�#�t�#�N�<�V�<�<�<�<rc�,�|�d��S)z�
        Kill the currently executing Lua script

        For more information check https://redis.io/commands/script-kill
        zSCRIPT KILLrrls r�script_killzScriptCommands.script_killXs���#�#�M�2�2�2rc�.�|�d|��S)z�
        Load a Lua ``script`` into the script cache. Returns the SHA.

        For more information check https://redis.io/commands/script-load
        zSCRIPT LOADr�rrNs  r�script_loadzScriptCommands.script_load`s���#�#�M�6�:�:�:rc�"�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.
        )�Scriptras  r�register_scriptzScriptCommands.register_scripths���d�F�#�#�#rrY)rZr[r\r]rQrUrWrYr]r_rbrer^rrrKrKs���������
M�M�M�M�M�M�<�<�<�
�
�
�
=�=�=�=�(3�3�3�;�;�;�$�$�$�$�$rrKc��eZdZdZdd�Zdd�Zd�Zd�Z									dd�Z									dd	�Z	d
�Z
													dd�Z											dd
�Zd�Z
dS)�GeoCommandszr
    Redis Geospatial commands.
    see: https://redis.com/redis-best-practices/indexing-patterns/geospatial/
    Fc�H�|r|rtd���t|��dzdkrtd���|g}|r|�d��|r|�d��|r|�d��|�|��|jdg|�R�S)	aC
        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 check https://redis.io/commands/geoadd
        z+GEOADD allows either 'nx' or 'xx', not both�rz4GEOADD requires places with lon, lat and name valuesr$r%�CH�GEOADD)rr�r,r}r
)rr�r�r'r(r�rs       r�geoaddzGeoCommands.geoaddxs���*�	K�"�	K��I�J�J�J��v�;�;��?�a����U�V�V�V����
�	 ��M�M�$����
�	 ��M�M�$����
�	 ��M�M�$�����
�
�f����#�t�#�H�6�v�6�6�6�6rNc��|||g}|r|dvrtd���|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 check https://redis.io/commands/geodist
        ��m�km�mi�ftzGEODIST invalid unit�GEODISTr~)rr��place1�place2�unitrs      r�geodistzGeoCommands.geodist�sg�����'���	 �D� 7�7�7��2�3�3�3�
�	 ��M�M�$����#�t�#�I�7��7�7�7�7rc� �|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 check https://redis.io/commands/geohash
        �GEOHASHrr�s   r�geohashzGeoCommands.geohash�s!��$�t�#�I�t�=�f�=�=�=�=rc� �|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 check https://redis.io/commands/geopos
        �GEOPOSrr�s   r�geoposzGeoCommands.geopos�s!��$�t�#�H�d�<�V�<�<�<�<rc�H�|�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 check https://redis.io/commands/georadius
        �	GEORADIUS�	rv�withdist�	withcoord�withhashr-r�r��
store_dist�any��_georadiusgeneric)rr��	longitude�latitude�radiusrvr�r�r�r-r�r�r�r�s              r�	georadiuszGeoCommands.georadius�sL��\�%�%�������������!��&�
�
�	
rc
�F�|�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 check https://redis.io/commands/georadiusbymember
        �GEORADIUSBYMEMBERr�r�)
rr��memberr�rvr�r�r�r-r�r�r�r�s
             r�georadiusbymemberzGeoCommands.georadiusbymember�sH��.�%�%������������!��&�
�
�	
rc��t|��}|dr|ddvrtd���|dr|�|d��n|�d��|dr|d�td���dD]"\}}||r|�|���#|d�:|�d	|dg��|dr|�d
��|drS|ddkr|�d��n1|dd
kr|�d
��ntd���|dr|drtd���|dr|�d|dg��|dr|�d|dg��|j|g|�Ri|��S)NrvrnzGEORADIUS invalid unitror�r-z+``any`` can't be provided without ``count``))r��WITHDIST)r��	WITHCOORD)r��WITHHASHr��ANYr��ASC�DESCzGEORADIUS invalid sortr�r�z3GEORADIUS store and store_dist cant be set togetherr��	STOREDIST)r�rr,r}r
�rr�r.rr�arg_name�	byte_reprs       rr�zGeoCommands._georadiusgeneric$s���d�����&�>�	�f�V�n�4K�K�K��4�5�5�5�
�F�^�	��M�M�&��.�)�)�)�)��M�M��
�
�
��%�=�	K�V�G�_�4��I�J�J�J�$
�	)�	)��H�i�
�h��
)��
�
�i�(�(�(���'�?�&��M�M�7�F�7�O�4�5�5�5��e�}�
%��
�
�e�$�$�$��&�>�	:��f�~��&�&��
�
�e�$�$�$�$����6�)�)��
�
�f�%�%�%�%�� 8�9�9�9��'�?�	V�v�l�3�	V��T�U�U�U��'�?�	7��M�M�8�V�G�_�5�6�6�6��,��	@��M�M�<���)=�>�?�?�?�#�t�#�G�?�f�?�?�?��?�?�?rroc�N�|�d|||||||||	|
|||
|dd���S)aG
        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 check https://redis.io/commands/geosearch
        �	GEOSEARCHN�r�r�r�rvr��width�heightr�r-r�r�r�r�r�r���_geosearchgeneric)rr�r�r�r�rvr�r�r�r�r-r�r�r�r�s               r�	geosearchzGeoCommands.geosearchRsU��h�%�%������������������#&�
�
�	
rc�P�|�d|||||||||	|
||dddd|
���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 check https://redis.io/commands/geosearchstore
        �GEOSEARCHSTORENr�r�)rrzr�r�r�r�rvr�r�r�r�r-r��	storedists              r�geosearchstorezGeoCommands.geosearchstore�sW��4�%�%������������������ �%&�
�
�	
rc�Z�t|��}|d�|d�|d�td���|dr<|ds|drtd���|�d|dg��|dr,|dr$|�d|d|dg��|d�|d	�|d
�td���|d�td
���|d���dvrtd���|drC|d	s|d
rtd���|�d|d|dg��|d	r3|d
r+|�d|d	|d
|dg��|drw|d���dkr|�d��nC|d���dkr|�d��ntd���|dr;|�d|dg��|dr|�d��n|drtd���dD]"\}}||r|�|���#|j|g|�Ri|��S)Nr�r�r�z4GEOSEARCH must have member or longitude and latitudez?GEOSEARCH member and longitude or latitude cant be set togethers
FROMMEMBERs
FROMLONLATr�r�r�z.GEOSEARCH must have radius or width and heightrvzGEOSEARCH must have unitrnzGEOSEARCH invalid unitz9GEOSEARCH radius and width or height cant be set togethersBYRADIUSsBYBOXr�r�sASCr�r�zGEOSEARCH invalid sortr-r�r�sANYz1GEOSEARCH ``any`` can't be provided without count))r�sWITHDIST)r�s	WITHCOORD)r�sWITHHASH)r�r�)r�rr}r|rAr,r
r�s       rr�zGeoCommands._geosearchgeneric�s/���d�����(��#��k�"�*�f�Z�.@�.H��M�����(��	=��k�"�
�f�Z�&8�
��X����
�M�M�=�&��*:�;�<�<�<��+��	T�6�*�#5�	T��M�M�=�&��*=�v�j�?Q�R�S�S�S��(��#��g��&�&��*:�*B�� S�T�T�T��&�>�!��6�7�7�7��&�>���!�!�)@�@�@��4�5�5�5��(��	K��g��
�&��"2�
��R����
�M�M�;��x�(8�&��.�I�J�J�J��'�?�	Y�v�h�/�	Y��M�M�8�V�G�_�f�X�6F��v��W�X�X�X��&�>�	:��f�~�#�#�%�%��.�.��
�
�f�%�%�%�%����%�%�'�'�6�1�1��
�
�g�&�&�&�&�� 8�9�9�9��'�?�	T��M�M�8�V�G�_�5�6�6�6��e�}�
&��
�
�f�%�%�%��
�E�]�	T��R�S�S�S�$
�	)�	)��H�i��h��
)��
�
�i�(�(�(��#�t�#�G�?�f�?�?�?��?�?�?r)FFFrY)	NFFFNNNNF)
NNNroNNNNNFFFF)NNNroNNNNNFF)rZr[r\r]rlrwrzr}r�r�r�r�r�r�r^rrrgrgrsj��������
!7�!7�!7�!7�F8�8�8�8� >�>�>�=�=�=� �����
����=
�=
�=
�=
�H�����
����%
�%
�%
�%
�N,@�,@�,@�b���
����
������F
�F
�F
�F
�X���
����
����-
�-
�-
�-
�^>@�>@�>@�>@�>@rrgc�<�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	S)
�ModuleCommandszO
    Redis Module commands.
    see: https://redis.io/topics/modules-intro
    c� �|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 check https://redis.io/commands/module-load
        zMODULE LOADr)r�pathr.s   r�module_loadzModuleCommands.module_loads!��$�t�#�M�4�?�$�?�?�?�?rc�.�|�d|��S)z�
        Unloads the module ``name``.
        Raises ``ModuleError`` if ``name`` is not in loaded modules.

        For more information check https://redis.io/commands/module-unload
        z
MODULE UNLOADrr�s  r�
module_unloadzModuleCommands.module_unloads���#�#�O�T�:�:�:rc�,�|�d��S)z�
        Returns a list of dictionaries containing the name and version of
        all loaded modules.

        For more information check https://redis.io/commands/module-list
        zMODULE LISTrrls r�module_listzModuleCommands.module_list#s���#�#�M�2�2�2rc� �td���r�r�rls rr�zModuleCommands.command_info,r�rc�,�|�d��S)Nr�rrls rr�zModuleCommands.command_count1s���#�#�O�4�4�4rc��|jdg|�R�S)NzCOMMAND GETKEYSrrTs  r�command_getkeyszModuleCommands.command_getkeys4s��#�t�#�$5�=��=�=�=�=rc�,�|�d��S)Nr�rrls rr�zModuleCommands.command7s���#�#�I�.�.�.rN)rZr[r\r]r�r�r�r�r�r�r�r^rrr�r�
s���������
@�@�@�;�;�;�3�3�3�
�
�
�
5�5�5�>�>�>�/�/�/�/�/rr�c�&�eZdZdZd�Zggdfd�ZdS)rdzI
    An executable Lua script object returned by ``register_script``
    c��||_||_t|t��r.|j���}|�|��}tj|���	��|_
dSrY)�registered_clientrNr+r{�connection_poolr=r?�hashlib�sha1�	hexdigestrT)rr�rNrLs    r�__init__zScript.__init__@sm��!2�������f�c�"�"�	,�(�7�C�C�E�E�G��^�^�F�+�+�F��<��'�'�1�1�3�3����rNc��|�|j}t|��t|��z}ddlm}t	||��r|j�|��	|j|jt|��g|�R�S#t$rC|�|j��|_|j|jt|��g|�R�cYSwxYw)z1Execute the script, passing any required ``args``Nr)�Pipeline)
r�r>r�r�r+�scripts�addrUrTr�rrbrN)rrHr.�clientr�s     r�__call__zScript.__call__Ls����>��+�F��T�{�{�U�4�[�[�(��)�)�)�)�)�)��f�h�'�'�	%��N���t�$�$�$�	>�!�6�>�$�(�C��I�I�=��=�=�=�=���	>�	>�	>��)�)�$�+�6�6�D�H�!�6�>�$�(�C��I�I�=��=�=�=�=�=�=�	>���s� A;�;A
C�C)rZr[r\r]r�r�r^rrrdrd;sJ��������
4�
4�
4��R��>�>�>�>�>�>rrdc�V�eZdZdZdd�Zd�Zd�Zdd�Zd�Zd�Z	e
d	���Zd
�ZdS)ruz0
    Command builder for BITFIELD commands.
    Nc�X�||_||_||_|���dSrY)r�rQ�_default_overflowrI)rr�rQrts    rr�zBitFieldOperation.__init__fs)��������!1����
�
�����rc�d�g|_d|_|�|jp|j��dS)zL
        Reset the state of the instance to when it was constructed
        �WRAPN)�
operations�_last_overflow�overflowr�rls rrIzBitFieldOperation.resetls6�����$����
�
�d�,�C��0C�D�D�D�D�Drc��|���}||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.
        �OVERFLOW)rAr�r�r,)rr�s  rr�zBitFieldOperation.overflowtsI���>�>�#�#���t�*�*�*�"*�D���O�"�"�J��#9�:�:�:��rc�p�|�|�|��|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.
        Nr�)r�r�r,)r�fmtr�	incrementr�s     rr�zBitFieldOperation.incrby�s@�����M�M�(�#�#�#������#�v�y�A�B�B�B��rc�@�|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.
        r��r�r,)rr�rs   rrUzBitFieldOperation.get�s&��	
�����s�F�3�4�4�4��rc�B�|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.
        r&r�)rr�rr�s    rr*zBitFieldOperation.set�s(��	
�����s�F�E�:�;�;�;��rc�V�d|jg}|jD]}|�|���|S)N�BITFIELD)rQr�r})rrP�opss   rr�zBitFieldOperation.command�s5���4�8�$���?�	�	�C��J�J�s�O�O�O�O��
rc�V�|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�rIr�r
)rr�s  r�executezBitFieldOperation.execute�s*���,���
�
����*�t�{�*�G�4�4rrY)
rZr[r\r]r�rIr�r�rUr*�propertyr�r�r^rrruruas�������������E�E�E��������(����������X��	5�	5�	5�	5�	5rruc�$�eZdZdZd�Zd�Zd�ZdS)�ClusterCommandsz*
    Class for Redis Cluster commands
    c�N�|jd|�����g|�Ri|��S)NzCLUSTER )r
rA)r�cluster_argr.rs    r�clusterzClusterCommands.cluster�s:��#�t�#�$D�{�/@�/@�/B�/B�$D�$D�V�t�V�V�V�v�V�V�Vrc��|jdi|��S)z�
        Disables read queries for a connection to a Redis Cluster slave node.

        For more information check https://redis.io/commands/readwrite
        �	READWRITE)r�rr#s  r�	readwritezClusterCommands.readwrite�r�rc��|jdi|��S)z�
        Enables read queries for a connection to a Redis Cluster replica node.

        For more information check https://redis.io/commands/readonly
        �READONLY)r�rr#s  r�readonlyzClusterCommands.readonly�r%rN)rZr[r\r]r�r�r�r^rrr�r��sN��������W�W�W�;�;�;�:�:�:�:�:rr�c��eZdZdZdS)�DataAccessCommandszx
    A class containing all of the implemented data access redis commands.
    This class is to be used as a mixin.
    N�rZr[r\r]r^rrr�r��s���������rr�c��eZdZdZdS)�CoreCommandszl
    A class containing all of the implemented redis commands. This class is
    to be used as a mixin.
    Nr�r^rrr�r��s���������rr�)r�r�rar]�redis.exceptionsrrrr�helpersrr
r`rjrmr�r�rr�rr
r=rKrgr�rdrur�r�r�r^rr�<module>r�s)������������������R�R�R�R�R�R�R�R�R�R�R�R�!�!�!�!�!�!�j<�j<�j<�j<�j<�j<�j<�j<�Z	vM�vM�vM�vM�vM�vM�vM�vM�rH6�H6�H6�H6�H6�H6�H6�H6�V{@�{@�{@�{@�{@�{@�{@�{@�|	_�_�_�_�_�_�_�_�DM@�M@�M@�M@�M@�M@�M@�M@�`G<�G<�G<�G<�G<�G<�G<�G<�T@
8�@
8�@
8�@
8�@
8�@
8�@
8�@
8�F?�?�?�?�?�?�?�?�@O:�O:�O:�O:�O:�O:�O:�O:�d&F�&F�&F�&F�&F�&F�&F�&F�R[$�[$�[$�[$�[$�[$�[$�[$�|U@�U@�U@�U@�U@�U@�U@�U@�p./�./�./�./�./�./�./�./�b#>�#>�#>�#>�#>�#>�#>�#>�L_5�_5�_5�_5�_5�_5�_5�_5�D:�:�:�:�:�:�:�:�2�����������������"����������������r