403Webshell
Server IP : 127.0.1.1  /  Your IP : 216.73.216.17
Web Server : Apache/2.4.58 (Ubuntu)
System : Linux dalsi.io 6.8.0-117-generic #117-Ubuntu SMP PREEMPT_DYNAMIC Tue May 5 19:26:24 UTC 2026 x86_64
User : www-data ( 33)
PHP Version : 8.3.6
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /lib/python3/dist-packages/redis/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /lib/python3/dist-packages/redis/__pycache__/cluster.cpython-312.pyc
�

���b
N�
��ddlZddlZddlZddlZddlZddlZddlZddlmZddl	m
Z
mZmZm
Z
ddlmZmZmZmZddlmZmZmZddlmZmZmZmZddlmZmZddlm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/dd	l0m1Z1dd
l2m3Z3m4Z4m5Z5m6Z6m7Z7ejpe9�Z:de;de<d
e;fd�Z=d�Z>d�Z?d�Z@de
de
d
ee
e<e<fee;e
fffd�ZAd�ZBdZCdZDdZEdZFdZGd�ZHGd�de�ZIGd�d�ZJGd �d!eJe�ZKGd"�d#�ZLGd$�d%�ZMGd&�d'�ZNGd(�d)e�ZOGd*�d+eK�ZPd,e;d
ed-e
ffd.�ZQd/ZReRD]2ZSeSj�d0d1�j��ZSeVePeSeQeS���4Gd2�d3�ZWGd4�d5�ZXy)6�N)�OrderedDict)�Any�Callable�Dict�Tuple)�CaseInsensitiveDict�PubSub�Redis�
parse_scan)�
READ_COMMANDS�CommandsParser�RedisClusterCommands)�ConnectionPool�
DefaultParser�Encoder�	parse_url)�REDIS_CLUSTER_HASH_SLOTS�key_slot)�AskError�AuthenticationError�BusyLoadingError�ClusterCrossSlotError�ClusterDownError�ClusterError�ConnectionError�	DataError�MasterDownError�
MovedError�RedisClusterException�
RedisError�
ResponseError�SlotNotCoveredError�TimeoutError�
TryAgainError��Lock)�
dict_merge�list_keys_to_dict�merge_result�safe_str�str_if_bytes�host�port�returnc��|�d|��S)N�:��r,r-s  �//usr/lib/python3/dist-packages/redis/cluster.py�
get_node_namer4-s���V�1�T�F���c�^�|jxs |jj|dfi|��S)Nr)�
connection�connection_pool�get_connection)�
redis_node�args�optionss   r3r9r91s:��� � ��$M�J�$>�$>�$M�$M��Q��%��%�r5c�t�i}g}|j�D]\}}t|fi|��\}}|||<||z
}� ||fS�N)�itemsr)	�command�resr<�cursors�ret�	node_name�response�cursor�rs	         r3�parse_scan_resultrH7sX���G�
�C�"�y�y�{���	�8��x�3�7�3�	���#��	���q����
�C�<�r5c���t�}|j�D]}|D]\}}	||xx|z
cc<��|j�D��cgc]	\}}||f��}}}|S#t$r|||<Y�NwxYwcc}}wr>)r�values�KeyErrorr?)	r@rAr<�numsub_d�numsub_tups�channel�	numsubbed�numsub�
ret_numsubs	         r3�parse_pubsub_numsubrRBs����}�H��z�z�|�.��"-�	.��G�Y�
.���!�Y�.�!�	.�.�<D�>�>�;K�L����7�F�#�L�J�L����	�
.�$-���!�
.��Ms�
A�A2�A/�.A/�respr<c���
�|jdd��
dtdtttff�
fd�}i}|D].}|dd\}}}|dd}||�|D�	cgc]}	||	���	c}	d�|||f<�0|Scc}	w)N�current_host�r;r.c�2��t|d�xs�|dfS�Nr�)r+)r;rUs �r3�
fix_serverz'parse_cluster_slots.<locals>.fix_serverTs ����D��G�$�4��d�1�g�=�=r5�)�primary�replicas)�getrr�str)rSr<rZ�slots�slot�start�endr\r]�replicarUs          @r3�parse_cluster_slotsreOs�����;�;�~�r�2�L�>�#�>�%��S��/�>�
�E��
��"�2�A�h���s�G����8��!�7�+�=E�F�'��W�-�F�
��e�S�j��
��L��Gs�A*c�`�g}|D]�}ggd�}tdt|d�d�D]'}|dj|d||d|dzf��)|d}|D]A}i}tdt|�d�D]}||dz|||<�|dj|��C|j|���|S)z(
    Parse CLUSTER SHARDS response.
    )r`�nodesrrY�r`r[rg)�range�len�append)	rSr<�shards�x�shard�irg�node�	dict_nodes	         r3�parse_cluster_shardsrrcs����F�
�
���r�*���q�#�a��d�)�Q�'�	<�A��'�N�!�!�1�Q�4��7�Q�q�T�!�a�%�[�":�;�	<��!����	-�D��I��1�c�$�i��+�
1��%)�!�a�%�[�	�$�q�'�"�
1��'�N�!�!�)�,�		-�
	�
�
�e��
��Mr5r\rdzslot-id)�charset�connection_classr8�client_name�db�decode_responses�encoding�encoding_errors�errorsr,�max_connections�
nodes_flag�redis_connect_func�passwordr-�retry�retry_on_timeout�socket_connect_timeout�socket_keepalive�socket_keepalive_options�socket_timeout�ssl�ssl_ca_certs�ssl_ca_data�ssl_certfile�
ssl_cert_reqs�ssl_keyfile�ssl_password�unix_socket_path�usernamer2c�x�|j�D��cic]\}}|tvr|tvr||��}}}|Scc}}w)z9
    Remove unsupported or disabled keys from kwargs
    )r?�REDIS_ALLOWED_KEYS�KWARGS_DISABLED_KEYS)�kwargs�k�v�connection_kwargss    r3�cleanup_kwargsr��sN���L�L�N���A�q��"�"�q�0D�'D�	
�1��������
s�6c
�@�eZdZeej
eeee	e
ed��Zy)�
ClusterParser)�ASK�TRYAGAIN�MOVED�CLUSTERDOWN�	CROSSSLOT�
MASTERDOWNN)�__name__�
__module__�__qualname__r'r�EXCEPTION_CLASSESrr$rrrrr1r5r3r�r��s-��"��'�'��%��+�.�)�
	
�
�r5r�c��eZdZdZdZdZdZdZdZeeeeehZ	e
egd�e�egd�e�ed	ge�egd
�e��Z
gd�fZeed�Ze
ed
ge�edgd��eddge�egd�d��eddgd��edgd��edge�edgd��edgd��edgd���
ZeeefZy )!�AbstractRedisCluster��	primariesr]�all�randomzdefault-node)GzACL CATzACL DELUSERz
ACL DRYRUNzACL GENPASSzACL GETUSERzACL HELPzACL LISTzACL LOGzACL LOADzACL SAVEzACL SETUSERz	ACL USERSz
ACL WHOAMI�AUTH�CLIENT LIST�CLIENT SETNAME�CLIENT GETNAME�
CONFIG SET�CONFIG REWRITE�CONFIG RESETSTAT�TIME�PUBSUB CHANNELS�
PUBSUB NUMPAT�
PUBSUB NUMSUB�PING�INFO�SHUTDOWN�KEYS�DBSIZE�BGSAVE�SLOWLOG GET�SLOWLOG LEN�
SLOWLOG RESET�WAIT�SAVE�MEMORY PURGEzMEMORY MALLOC-STATSzMEMORY STATS�LASTSAVEzCLIENT TRACKINGINFO�CLIENT PAUSE�CLIENT UNPAUSE�CLIENT UNBLOCKz	CLIENT IDzCLIENT REPLYzCLIENT GETREDIRzCLIENT INFO�CLIENT KILL�READONLY�	READWRITEzCLUSTER INFOzCLUSTER MEETz
CLUSTER NODESzCLUSTER REPLICASz
CLUSTER RESETzCLUSTER SET-CONFIG-EPOCH�
CLUSTER SLOTS�CLUSTER SHARDSzCLUSTER COUNT-FAILURE-REPORTSzCLUSTER KEYSLOT�COMMANDz
COMMAND COUNTzCOMMAND LISTzCOMMAND GETKEYS�
CONFIG GET�DEBUG�	RANDOMKEYr�r�r�zGRAPH.CONFIG)�FLUSHALL�FLUSHDBzFUNCTION DELETEzFUNCTION FLUSHz
FUNCTION LISTz
FUNCTION LOADzFUNCTION RESTORE�SCAN�
SCRIPT EXISTS�SCRIPT FLUSH�SCRIPT LOADz
FUNCTION DUMP)zCLUSTER COUNTKEYSINSLOTzCLUSTER DELSLOTSzCLUSTER DELSLOTSRANGEzCLUSTER GETKEYSINSLOTzCLUSTER SETSLOT)z	FT.CREATEz	FT.SEARCHzFT.AGGREGATEz
FT.EXPLAINz
FT.EXPLAINCLIz
FT,PROFILEzFT.ALTERzFT.DROPINDEXzFT.ALIASADDzFT.ALIASUPDATEzFT.ALIASDELz
FT.TAGVALSz	FT.SUGADDz	FT.SUGGETz	FT.SUGDELz	FT.SUGLENzFT.SYNUPDATEz
FT.SYNDUMPz
FT.SPELLCHECKz
FT.DICTADDz
FT.DICTDELzFT.DICTDUMPzFT.INFOzFT._LISTz	FT.CONFIGzFT.ADDzFT.DELzFT.DROPzFT.GETzFT.MGETz	FT.SYNADD)r�r�r�r�c�F�tt|j���Sr>)�sum�listrJ�r@rAs  r3�<lambda>zAbstractRedisCluster.<lambda>Zs��C��S�Z�Z�\�8J�4K�r5r�r�)r�r�r�r�r�r�r�r�r�r�r�c�X�t|t�rt|j��S|Sr>)�
isinstance�dictr�rJr�s  r3r�zAbstractRedisCluster.<lambda>k���j��d�6K��S�Z�Z�\�!2��QT�r5r�r�c�X�t|t�rt|j��S|Sr>)r�r�r�rJr�s  r3r�zAbstractRedisCluster.<lambda>or�r5r�c�B�t|j��dkDrdSdSrX)r�rJr�s  r3r�zAbstractRedisCluster.<lambda>rs��#�c�j�j�l�:K�a�:O�Q��UV�r5r�r�c�P�t|j��j�Sr>)r�rJ�popr�s  r3r�zAbstractRedisCluster.<lambda>vs��$�s�z�z�|�2D�2H�2H�2J�r5r�c�f�t|j��D�cgc]
}t|���c}Scc}wr>)�ziprJr�)r@rAr�s   r3r�zAbstractRedisCluster.<lambda>ys#��S�#�*�*�,�EW�4X��S��V�4X���4Xs�.r�c�4�t|j��Sr>)r�rJr�s  r3r�zAbstractRedisCluster.<lambda>{s���S�Z�Z�\�AR�r5N)r�r�r��RedisClusterRequestTTL�	PRIMARIES�REPLICAS�	ALL_NODES�RANDOM�DEFAULT_NODE�
NODE_FLAGSr'r(�SLOT_ID�
COMMAND_FLAGS�SEARCH_COMMANDSrerr�#CLUSTER_COMMANDS_RESPONSE_CALLBACKSrRr)rH�RESULT_CALLBACKSrr#r�ERRORS_ALLOW_RETRYr1r5r3r�r��st�����I��H��I�
�F�!�L��X�y�&�,�G�J���H
�R
�UK	
�X	�
�
�	
� 	�?�+�V�4��
�
�		
�}h�M�V 	
�"�O�J-�.�+�'�
"��?�+�-@�A��
��K�	
�	�6�#4�5�|�D��
�
U�	
� 	�
�v��T�	
�	�
�� V�	
�	�6�(�$5�6��
�O�J�	
�	�
��X�	
�	�>�*�,R�S�I%��N*�<�9I�J�r5r�c��eZdZed��Z									d%d�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd&d
�Zd�Z
d�Zd
�Zd�Zd'd�Zd�Zd�Zd(d�Zd&d�Zd)d�Z						d*d�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z d�Z!d �Z"d!�Z#d"�Z$d#�Z%d$�Z&y)+�RedisClusterc��|dd|i|��S)a
        Return a Redis client object configured from the given URL

        For example::

            redis://[[username]:[password]]@localhost:6379/0
            rediss://[[username]:[password]]@localhost:6379/0
            unix://[[username]:[password]]@/path/to/socket.sock?db=0

        Three URL schemes are supported:

        - `redis://` creates a TCP socket connection. See more at:
          <https://www.iana.org/assignments/uri-schemes/prov/redis>
        - `rediss://` creates a SSL wrapped TCP socket connection. See more at:
          <https://www.iana.org/assignments/uri-schemes/prov/rediss>
        - ``unix://``: creates a Unix Domain Socket connection.

        The username, password, hostname, path and all querystring values
        are passed through urllib.parse.unquote in order to replace any
        percent-encoded values with their corresponding characters.

        There are several ways to specify a database number. The first value
        found will be used:

            1. A ``db`` querystring option, e.g. redis://localhost?db=0
            2. If using the redis:// or rediss:// schemes, the path argument
               of the url, e.g. redis://localhost/0
            3. A ``db`` keyword argument to this function.

        If none of these options are specified, the default db=0 is used.

        All querystring options are cast to their appropriate Python types.
        Boolean arguments can be specified with string values "True"/"False"
        or "Yes"/"No". Values that cannot be properly cast cause a
        ``ValueError`` to be raised. Once parsed, the querystring arguments
        and keyword arguments are passed to the ``ConnectionPool``'s
        class initializer. In the case of conflicting arguments, querystring
        arguments always win.

        �urlr1r1)�clsr�r�s   r3�from_urlzRedisCluster.from_url�s��T�%�s�%�f�%�%r5Nc
���|�g}d|
vrtd��d}|	��d}t|	�}d|vrtd��d|vr|ddk7rtd	��|
j|�|
jd
�}|
jd|�}|j	t||��n9|�|�|j	t||��nt
|�dk(rtd��tjd
|���|
jdd�|_
|
jd|ji�tdi|
��}
t|
jdd�|
jdd�|
jdd��|_||_|j j"j%�|_|j j(j%�|_||_d|_||_d|_t5d||||d�|
��|_t7|j j8�|_t7|j j<�|_tA|�|_!tEjF�|_$y)a�
         Initialize a new RedisCluster client.

         :startup_nodes: 'list[ClusterNode]'
             List of nodes from which initial bootstrapping can be done
         :host: 'str'
             Can be used to point to a startup node
         :port: 'int'
             Can be used to point to a startup node
         :require_full_coverage: 'bool'
            When set to False (default value): the client will not require a
            full coverage of the slots. However, if not all slots are covered,
            and at least one node has 'cluster-require-full-coverage' set to
            'yes,' the server will throw a ClusterDownError for some key-based
            commands. See -
            https://redis.io/topics/cluster-tutorial#redis-cluster-configuration-parameters
            When set to True: all slots must be covered to construct the
            cluster client. If not all slots are covered, RedisClusterException
            will be thrown.
        :read_from_replicas: 'bool'
             Enable read from replicas in READONLY mode. You can read possibly
             stale data.
             When set to true, read commands will be assigned between the
             primary and its replications in a Round-Robin manner.
         :dynamic_startup_nodes: 'bool'
             Set the RedisCluster's startup nodes to all of the discovered nodes.
             If true (default value), the cluster's discovered nodes will be used to
             determine the cluster nodes-slots mapping in the next topology refresh.
             It will remove the initial passed startup nodes if their endpoints aren't
             listed in the CLUSTER SLOTS output.
             If you use dynamic DNS endpoints for startup nodes but CLUSTER SLOTS lists
             specific IP addresses, it is best to set it to false.
        :cluster_error_retry_attempts: 'int'
             Retry command execution attempts when encountering ClusterDownError
             or ConnectionError
        :reinitialize_steps: 'int'
            Specifies the number of MOVED errors that need to occur before
            reinitializing the whole cluster topology. If a MOVED error occurs
            and the cluster does not need to be reinitialized on this current
            error handling, only the MOVED slot will be patched with the
            redirected node.
            To reinitialize the cluster on every MOVED error, set
            reinitialize_steps to 1.
            To avoid reinitializing the cluster on moved errors, set
            reinitialize_steps to 0.

         :**kwargs:
             Extra arguments that will be sent into Redis instance when created
             (See Official redis-py doc for supported kwargs
         [https://github.com/andymccurdy/redis-py/blob/master/redis/client.py])
             Some kwargs are not supported and will raise a
             RedisClusterException:
                 - db (Redis do not support database SELECT in cluster mode)
        Nrvz4Argument 'db' is not possible to use in cluster modeFT�pathzFRedisCluster does not currently support Unix Domain Socket connectionsrz9A ``db`` querystring option can only be 0 in cluster moder,r-a5RedisCluster requires at least one node to discover the cluster. Please provide one of the followings:
1. host and port, for example:
 RedisCluster(host='localhost', port=6379)
2. list of startup nodes, for example:
 RedisCluster(startup_nodes=[ClusterNode('localhost', 6379), ClusterNode('localhost', 6378)])zstartup_nodes : r}rx�utf-8ry�strictrw)�
startup_nodesr��require_full_coverage�dynamic_startup_nodesr1)%rr�updater^rk�ClusterNoderj�log�debugr��user_on_connect_func�
on_connectr�r�encoder�cluster_error_retry_attempts�	__class__r��copy�
command_flagsr��
node_flags�read_from_replicas�reinitialize_counter�reinitialize_steps�
nodes_manager�NodesManagerrr��cluster_response_callbacksr��result_callbacksr
�commands_parser�	threadingr&�_lock)
�selfr,r-r�rr�r
rr�r�r�r��url_optionss
             r3�__init__zRedisCluster.__init__�s`��F� ��M��6�>�'�F��
�
���?��H�#�C�.�K���$�+�)����{�"�{�4�'8�A�'=�+�O���
�M�M�+�&��:�:�f�%�D��:�:�f�d�+�D�� � ��T�4�!8�9�
�
�$�"2�� � ��T�4�!8�9�
��
�1�
$�'�4��
�	�	�	�$�]�O�4�5�%+�J�J�/C�T�$J��!��
�
�+�T�_�_�=�>��)�&�)����J�J�z�7�+��J�J�(�(�3��J�J�)�5�1�
���
-I��)�!�^�^�9�9�>�>�@����.�.�3�3�8�8�:���"4���$%��!�"4���!���)�
�'��"7�"7�	
�
�
���+>��N�N�>�>�+
��'�!4�D�N�N�4S�4S� T���-�d�3����^�^�%��
r5c��|Sr>r1�rs r3�	__enter__zRedisCluster.__enter__?s���r5c�$�|j�yr>��close�r�exc_type�	exc_value�	tracebacks    r3�__exit__zRedisCluster.__exit__B����
�
�r5c�$�|j�yr>rrs r3�__del__zRedisCluster.__del__Er r5c��|j�D]4}|js�	|jjj��6y#t$rY�CwxYwr>)�	get_nodes�redis_connectionr8�
disconnect�OSError�rrps  r3�disconnect_connection_poolsz(RedisCluster.disconnect_connection_poolsHsR���N�N�$�	�D��$�$���)�)�9�9�D�D�F�	������s�$A	�		A�Ac��|jt�|j�|jr8|j	d�t|j
��dk7rtd��|j�|j|�yy)z�
        Initialize the connection, authenticate and select a database and send
         READONLY if it is set during object initialization.
        r��OKzREADONLY command failedN)	�
set_parserr�rr�send_commandr+�
read_responserr)rr7s  r3rzRedisCluster.on_connectQsx��
	���m�,������"�"�
�#�#�J�/��J�4�4�6�7�4�?�%�&?�@�@��$�$�0��%�%�j�1�1r5c���|jsI|j5|js|jj|g�ddd�|jS|jS#1swY|jSxYwr>)r%rr�create_redis_connectionsr(s  r3�get_redis_connectionz!RedisCluster.get_redis_connectionfsk���$�$����
H��,�,��&�&�?�?���G�
H��$�$�$�t�$�$�$�
H��$�$�$�s�)A"�"A6c�<�|jj|||�Sr>)r�get_node�rr,r-rDs    r3r3zRedisCluster.get_nodems���!�!�*�*�4��y�A�Ar5c�@�|jjt�Sr>)r�get_nodes_by_server_type�PRIMARYrs r3�
get_primarieszRedisCluster.get_primariesp����!�!�:�:�7�C�Cr5c�@�|jjt�Sr>)rr6�REPLICArs r3�get_replicaszRedisCluster.get_replicassr9r5c��tjt|jjj���Sr>)r��choicer�r�nodes_cacherJrs r3�get_random_nodezRedisCluster.get_random_nodevs+���}�}�T�$�"4�"4�"@�"@�"G�"G�"I�J�K�Kr5c�\�t|jjj��Sr>)r�rr?rJrs r3r$zRedisCluster.get_nodesys"���D�&�&�2�2�9�9�;�<�<r5c��|j|�}|jjj|�}|�t	|�dk(rtd|�d���|r&t	|jj|�dkry|rd}||Sd}||S)z�
        Get the node that holds the key's slot.
        If replica set to True but the slot doesn't have any replicas, None is
        returned.
        Nr�Slot "z " is not covered by the cluster.rhrY)�keyslotr�slots_cacher^rjr")r�keyrdra�
slot_cache�node_idxs      r3�get_node_from_keyzRedisCluster.get_node_from_key|s����|�|�C� ���'�'�3�3�7�7��=�
����Z��A�!5�%��t�f�4T�&U�V�V��s�4�-�-�9�9�$�?�@�1�D��
��H�
�(�#�#��H��(�#�#r5c�.�|jjS)z0
        Get the cluster's default node
        )r�default_noders r3�get_default_nodezRedisCluster.get_default_node�s���!�!�.�.�.r5c��|�|j|j���tjd�y||j_tjd|���y)z�
        Set the default node of the cluster.
        :param node: 'ClusterNode'
        :return True if the default node was set, else False
        �rDzVThe requested node does not exist in the cluster, so the default node was not changed.Fz$Changed the default cluster node to T)r3�namer��inforrKr(s  r3�set_default_nodezRedisCluster.set_default_node�sX���<�4�=�=�4�9�9�=�=�E��H�H�4�
��*.����'����7��v�>�?�r5c��|�|j�}|j�td|j�d���|jj	�S)ai
        Returns a Monitor object for the specified target node.
        The default cluster node will be selected if no target node was
        specified.
        Monitor is useful for handling the MONITOR command to the redis server.
        next_command() method returns one command from monitor
        listen() method yields commands from monitor.
        z
Cluster Node z has no redis_connection)rLr%rrO�monitor)r�target_nodes  r3rSzRedisCluster.monitor�s\�����/�/�1�K��'�'�/�'��� 0� 0�1�1I�J��
��+�+�3�3�5�5r5c�"�t|f|||d�|��S)z~
        Allows passing a ClusterNode, or host&port, to get a pubsub instance
        connected to the specified node
        )rpr,r-)�
ClusterPubSub)rrpr,r-r�s     r3�pubsubzRedisCluster.pubsub�s��
�T�M��4�d�M�f�M�Mr5c�&�|rtd��|rtd��t|j|j|jj|j
|j|j|j|j|j��	S)ac
        Cluster impl:
            Pipelines do not work in cluster mode the same way they
            do in normal mode. Create a clone of this object so
            that simulating pipelines will work correctly. Each
            command will be called directly when used and
            when calling execute() will only return the result stack.
        z(shard_hint is deprecated in cluster modez)transaction is deprecated in cluster mode)	rrr�rr
rrr
�lock)r�ClusterPipelinerrr�rr
rrr
r)r�transaction�
shard_hints   r3�pipelinezRedisCluster.pipeline�s����'�(R�S�S��'�(S�T�T���,�,� �0�0��,�,�:�:�!�2�2�'+�'F�'F�)-�)J�)J�#�6�6�#�6�6����

�
	
r5c	�0�|�t}||||||||��S)aL
        Return a new Lock object using key ``name`` that mimics
        the behavior of threading.Lock.

        If specified, ``timeout`` indicates a maximum life for the lock.
        By default, it will remain locked until release() is called.

        ``sleep`` indicates the amount of time to sleep per loop iteration
        when the lock is in blocking mode and another client is currently
        holding the lock.

        ``blocking`` indicates whether calling ``acquire`` should block until
        the lock has been acquired or to fail immediately, causing ``acquire``
        to return False and the lock not being acquired. Defaults to True.
        Note this value can be overridden by passing a ``blocking``
        argument to ``acquire``.

        ``blocking_timeout`` indicates the maximum amount of time in seconds to
        spend trying to acquire the lock. A value of ``None`` indicates
        continue trying forever. ``blocking_timeout`` can be specified as a
        float or integer, both representing the number of seconds to wait.

        ``lock_class`` forces the specified lock implementation. Note that as
        of redis-py 3.0, the only lock class we implement is ``Lock`` (which is
        a Lua-based lock). So, it's unlikely you'll need this parameter, unless
        you have created your own custom lock class.

        ``thread_local`` indicates whether the lock token is placed in
        thread-local storage. By default, the token is placed in thread local
        storage so that a thread only sees its token, not a token set by
        another thread. Consider the following timeline:

            time: 0, thread-1 acquires `my-lock`, with a timeout of 5 seconds.
                     thread-1 sets the token to "abc"
            time: 1, thread-2 blocks trying to acquire `my-lock` using the
                     Lock instance.
            time: 5, thread-1 has not yet completed. redis expires the lock
                     key.
            time: 5, thread-2 acquired `my-lock` now that it's available.
                     thread-2 sets the token to "xyz"
            time: 6, thread-1 finishes its work and calls release(). if the
                     token is *not* stored in thread local storage, then
                     thread-1 would see the token value as "xyz" and would be
                     able to successfully release the thread-2's lock.

        In some use cases it's necessary to disable thread local storage. For
        example, if you have code where one thread acquires a lock and passes
        that lock instance to a worker thread to release later. If thread
        local storage isn't disabled in this case, the worker thread won't see
        the token set by the thread that acquired the lock. Our assumption
        is that these cases aren't common and as such default to using
        thread local storage.)�timeout�sleep�blocking�blocking_timeout�thread_localr%)rrOr_r`rarb�
lock_classrcs        r3rYzRedisCluster.lock�s2��|���J�������-�%�
�	
r5c�"�||j|<y)zSet a custom Response CallbackN)r
)rr@�callbacks   r3�set_response_callbackz"RedisCluster.set_response_callback#s��3;��'�'��0r5c�.�|dj�}t|�dk\rB|d�d|d��j�|jvr|d�d|d��j�}|jdd�}|�|}n|jj	|�}|rt
j
d|�d|���||jjk(r|j�gS||jjk(r|j�S||jjk(r|j�S||jjk(r|j�S||jj k(r|j"j$gS||jj&dvr|j"j$gS|j(|�}|j"j+||j,xr|t.v�}t
j
d|�d	|���|gS)
Nrrh� rYr|zTarget node/s for z: zTarget for z: slot )�upperrjrr�r^r�r�rr�r@r�r8r�r<r�r$r�rrKr��determine_slot�get_node_from_slotrr)rr;r�r@r|�command_flagrarps        r3�_determine_nodeszRedisCluster._determine_nodes's����q�'�-�-�/���t�9��>��a��	��4��7�)�4�:�:�<��@R�@R�R��a��	��4��7�)�,�2�2�4�G��Z�Z��d�3�
��!�%�L� �-�-�1�1�'�:�L���I�I�*�7�)�2�l�^�D�E��4�>�>�0�0�0��(�(�*�+�+�
�T�^�^�5�5�
5��%�%�'�'�
�T�^�^�4�4�
4��$�$�&�&�
�T�^�^�5�5�
5��>�>�#�#�
�T�^�^�8�8�
8��&�&�3�3�4�4�
����6�6�q�9�
9��&�&�3�3�4�4�'�4�&�&��-�D��%�%�8�8��d�-�-�J�'�]�2J��D�
�I�I��D�6����7�8��6�Mr5c�Z�|jdk(ry|j|jzdk(S)NrF)r
r	rs r3�_should_reinitializedz"RedisCluster._should_reinitializedOs1��
�"�"�a�'���,�,�t�/F�/F�F�!�K�Kr5c�N�|jj|�}t|�S)z�
        Calculate keyslot for a given key.
        See Keys distribution model in https://redis.io/topics/cluster-spec
        )r�encoder)rrFr�s   r3rDzRedisCluster.keyslotYs"��

�L�L����$����{�r5c�p�|j�j}|jj|g|���S)a�
        Get the keys in the command. If the command has no keys in in, None is
        returned.

        NOTE: Due to a bug in redis<7.0, this function does not work properly
        for EVAL or EVALSHA when the `numkeys` arg is 0.
         - issue: https://github.com/redis/redis/issues/9493
         - fix: https://github.com/redis/redis/pull/9733

        So, don't use this function with EVAL or EVALSHA.
        )rLr%r�get_keys)rr;�
redis_conns   r3�_get_command_keyszRedisCluster._get_command_keysas6���*�*�,�=�=�
�,�t�#�#�,�,�Z�?�$�?�?r5c��|d}|jj|�tk(r|dS|dvrTt|�dkrt	d|����|d}|dd|z}t|�dk(rtjdt�S|}nK|j|�}|�t|�dk(r,|dvrtjdt�St	d|����t|�dk(r|j|d�S|D�chc]}|j|���}}t|�dk7rt	|�d	���|j�Scc}w)
a
        Figure out what slot to use based on args.

        Raises a RedisClusterException if there's a missing key and we can't
            determine what slots to map the command to; or, if the keys don't
            all map to the same key slot.
        rrY)�EVAL�EVALSHArhzInvalid args in command: r[)�FCALL�FCALL_ROz�No way to dispatch this command to Redis Cluster. Missing key.
You can execute the command by specifying target nodes.
Command: z) - all keys must map to the same key slot)rr^r�rjrr��	randrangerrvrDr�)rr;r@�num_actual_keys�	eval_keys�keysrFr`s        r3rkzRedisCluster.determine_slotpsi���q�'�����!�!�'�*�g�5���7�N��)�)��4�y�A�~�+�.G��v�,N�O�O�"�1�g�O��Q��_�!4�5�I��9�~��"��'�'��+C�D�D��D�)�4�)�)�4�0�D��|�s�4�y�A�~��3�3�!�+�+�A�/G�H�H�+�/�/3�f�6����t�9��>��<�<��Q��(�(�/3�3�s����c�"�3��3��u�:��?�'��)�D�E��
��y�y�{���
4s�6D<c��|jS)z.
        Get the connections' encoder
        )rrs r3�get_encoderzRedisCluster.get_encoder�s���|�|�r5c�.�|jjS)z9
        Get the connections' key-word arguments
        )rr�rs r3�get_connection_kwargsz"RedisCluster.get_connection_kwargs�s���!�!�3�3�3r5c�B�t|t�xr||jvSr>)r�r_r)r�target_nodess  r3�_is_nodes_flagzRedisCluster._is_nodes_flag�s���,��,�P�����1P�Pr5c���t|t�r|}|St|t�r|g}|St|t�r|j	�}|Stdt
|�����)Nz�target_nodes type can be one of the following: node_flag (PRIMARIES, REPLICAS, RANDOM, ALL_NODES),ClusterNode, list<ClusterNode>, or dict<any, ClusterNode>. The passed type is )r�r�r�r�rJ�	TypeError�type)rr�rgs   r3�_parse_target_nodesz RedisCluster._parse_target_nodes�s{���l�D�)� �E� ����k�
2�!�N�E�����d�
+�!�'�'�)�E���
�&�'+�<�&8�%9�;��
r5c��d}d}|jdd�}|�$|j|�s|j|�}d}|rdn|j}d}t	d|�D]p}	i}	|s'|j
|i|�d|i��}|st
d|�d	���|D]%}
|j|
g|��i|��|	|
j<�'|j|d|	fi|��cS|�#t$r0}t|�|jjvr|}n|�Yd}~��d}~wwxYw)
a"
        Wrapper for ERRORS_ALLOW_RETRY error handling.

        It will try the number of times specified by the config option
        "self.cluster_error_retry_attempts" which defaults to 3 unless manually
        configured.

        If it reaches the number of times, the command will raise the exception

        Key argument :target_nodes: can be passed with the following types:
            nodes_flag: PRIMARIES, REPLICAS, ALL_NODES, RANDOM
            ClusterNode
            list<ClusterNode>
            dict<Any, ClusterNode>
        FNr�TrYrr|�!No targets were found to execute � command on)r�r�r�rrirnr�_execute_commandrO�_process_result�
BaseExceptionr�rr�)rr;r��target_nodes_specifiedr��passed_targets�retry_attempts�	exception�_rArp�es            r3�execute_commandzRedisCluster.execute_command�sb�� "'�������N�D�9���%�d�.A�.A�.�.Q��3�3�N�C�L�%)�"�(�A�T�-N�-N�	��	��q�.�)�	�A�
���-�#8�4�#8�#8��$�!'�$�4B�$�L�(�3�?��v�[�Q���)�R�D�%:�T�%:�%:�4�%Q�$�%Q�&�%Q�C��	�	�N�R�,�t�+�+�D��G�S�C�F�C�C�	�6���!�
���7�d�n�n�?�?�?�!"�I��G���	
�s�A+C�	D	�&D�D	c��|d}d}d}d}d}d}	t|j�}
d}|
dkD�r@|
dz}
	|r|j|��}nC|	rA|j|�}|jj||jxr|tv�}d}	tjd|�d|j�d|j���|j|�}t|g|��i|��}|r'|jd	�|j|d	fi|��d}|j|�|j||fi|��}
||j vr|j ||
fi|��}
|
|�|j"j%|�SStYd��#t&t(t*f$r$}tj-t/|���d}~wt0t2f$r}}tj-t/|��|�|j5�|dz
}|d
krt7j8d�n"d|_|jj=��Yd}~�n�d}~wt>$r�}tj-d�|xj@dz
c_ |jC�r"|jj=�d|_ n|jjE|�d
}	Yd}~�nUd}~wtF$r@tj-d�|
|jdzkrt7j8d�Y�n
tH$rB}tj-d�tK|jL|jN��}d
}Yd}~n�d}~wtP$rK}tj-d�t7j8d�|jj=�|�d}~wtR$r/}|jU�}tj-d|���|�d}~wtV$r.}tj-d�|r|j5�|�d}~wwxYw|�?|j"j%|�n##|�|j"j%|�wwxYw|
dkDr��0���)z9
        Send a command to a node in the cluster
        rNFrYrNzExecuting command z on target node: ri�ASKING�g�?rTr$rhg�������?rr2rzResponseError: r�zTTL exhausted.)-�intr�r3rkrrlrrr�r��server_typerOr1r9r-�parse_responser
r8�releaserrrr�r�rr#r&�timer`r%�
initializerr	rp�update_moved_exceptionr$rr4r,r-rr!�__str__r�r)rrTr;r�r@r:r7�
redirect_addr�asking�moved�ttl�connection_error_retry_counterrarEr��messages                r3r�zRedisCluster._execute_commands���q�'���
��
��
������$�-�-�.��)*�&��A�g��1�H�C�f
C��"&�-�-�-�-�"H�K��/�4�.�.��5�D�"&�"4�"4�"G�"G��d�5�5�R�'�]�:R�#�K�"�E��	�	�(��	�1B�"�.�.�/�q��1A�1A�0B�D��"�6�6�{�C�
�+�J�H��H��H�
���+�+�H�5�-�J�-�-�j�(�M�f�M�"�F�'�
�'�'��.�4�:�4�4�Z��S�F�S���d�=�=�=�G�t�>�>�w�G� � �$*� �H� �P�)��.�.�6�6�z�B�*��+�,�,��S*�+;�=P�Q�
��
�
�d�1�g�&���#�\�2�
��
�
�d�1�g�&��)��)�)�+�.�!�3�.�2�A�5��J�J�t�$�48�K�0��&�&�1�1�3��
%���
��
�
�l�+��)�)�Q�.�)��-�-�/��&�&�1�1�3�01�D�-��&�&�=�=�a�@���� �
%��
�
�o�.���4�4�q�8�8��J�J�t�$���
��
�
�j�)� -�1�6�6���� G�
����#�
��
�
�0�1��
�
�4� ��"�"�-�-�/���� �
��)�)�+���
�
���y�9�:���� �
��
�
�o�.���)�)�+����	
���)��.�.�6�6�z�B���)��.�.�6�6�z�B�*��O�A�g�s��DE8�8P�F+�+P�=A2H5�/P3�5P�A9K�:P3�AP�P3�P�8M�P3�P�AN"�"P�.*O�P�$)P
�
P�P3�3 Qc��	|j5|jr|jj�ddd�y#1swYyxYw#t$rYywxYwr>)rrr�AttributeErrorrs r3rzRedisCluster.close�sQ��	����
/��%�%��&�&�,�,�.�
/�
/�
/���	��	�s+�A
�'>�A
�A�A
�A
�
	A�Ac��||jvr|j|||fi|��St|�dk(rt|j��dS|S)a
        Process the result of the executed command.
        The function would return a dict or a single value.

        :type command: str
        :type res: dict

        `res` should be in the following format:
            Dict<node_name, command_result>
        rYr)rrjr�rJ)rr@rAr�s    r3r�zRedisCluster._process_result�sY���d�+�+�+�1�4�(�(��1�'�3�I�&�I�I�
��X��]���
�
��%�a�(�(��Jr5c��t|||�y)a
        This function can be used to add externally defined redis modules,
        and their namespaces to the redis client.

        ``funcname`` - A string containing the name of the function to create
        ``func`` - The function, being added to this class.
        N)�setattr)r�funcname�funcs   r3�load_external_modulez!RedisCluster.load_external_module�s��	��h��%r5)	Ni�Nr[F�
FTN�NNN)Fr>�NN)Ng�������?TNNT)'r�r�r��classmethodr�rrrr"r)rr1r3r8r<r@r$rIrLrQrSrWr]rYrgrnrprDrvrkr�r�r�r�r�r�rr�r�r1r5r3r�r��s���)&��)&�Z�
��%&�#�� �"��O&�b����2�*%�B�D�D�L�=�$�(/�� 6�"N�
�<������H
�T<�&�PL��
@�7�r�4�Q��(=�~w-�r��(&r5r�c�&�eZdZdd�Zd�Zd�Zd�Zy)r�Nc��|dk(rtj|�}||_||_t	||�|_||_||_y)N�	localhost)�socket�
gethostbynamer,r-r4rOr�r%)rr,r-r�r%s     r3rzClusterNode.__init__�sF���;���'�'��-�D���	���	�!�$��-��	�&��� 0��r5c��d|j�d|j�d|j�d|j�d|j�d�S)Nz[host=z,port=z,name=z
,server_type=z,redis_connection=�])r,r-rOr�r%rs r3�__repr__zClusterNode.__repr__�sW���T�Y�Y�K� ��I�I�;���I�I�;���+�+�,�- � $� 5� 5�6�a�	
9�	
r5c�X�t|t�xr|j|jk(Sr>)r�r�rO)r�objs  r3�__eq__zClusterNode.__eq__�s!���#�{�+�E����D�I�I�0E�Er5c�R�|j�|jj�yyr>)r%rrs r3r"zClusterNode.__del__�s%��� � �,��!�!�'�'�)�-r5r�)r�r�r�rr�r�r"r1r5r3r�r��s��1�
�F�*r5r�c�>�eZdZdZd
deddfd�Zdededefd�Zdd	�Zy)�LoadBalancerz$
    Round-Robin Load Balancing
    �start_indexr.Nc� �i|_||_yr>)�primary_to_idxr�)rr�s  r3rzLoadBalancer.__init__�s�� ���&��r5r\�	list_sizec�|�|jj||j�}|dz|z|j|<|S)NrY)r��
setdefaultr�)rr\r��server_indexs    r3�get_server_indexzLoadBalancer.get_server_index�s@���*�*�5�5�g�t�?O�?O�P��(4�q�(8�I�'E����G�$��r5c�8�|jj�yr>)r��clearrs r3�resetzLoadBalancer.reset�s�����!�!�#r5)r)r.N)	r�r�r��__doc__r�rr_r�r�r1r5r3r�r��s9���'�C�'��'��������$r5r�c�n�eZdZ				dd�Zdd�Zd�Zd�Zdd�Zd�Zd�Z	d	�Z
d
�Zd�Zd�Z
d
�Zd�Zd�Zy)rNc��i|_i|_i|_d|_|j	|�||_||_||_d|_||_	t�|_|�tj�}||_|j�yr>)r?rEr�rK�populate_startup_nodesr��_require_full_coverage�_dynamic_startup_nodes�_moved_exceptionr�r��read_load_balancerrr&rr�)rr�r�r�rYr�r�s       r3rzNodesManager.__init__�s������������ ����#�#�M�2� ��
�&;��#�&;��#� $���!'���".�.����<��>�>�#�D���
����r5c���|rB|r@|dk(rtj|�}|jjt	||���S|r|jj|�St
j
d�y)z�
        Get the requested node from the cluster's nodes.
        nodes.
        :return: ClusterNode if the node exists, else None
        r�r2zEget_node requires one of the following: 1. node name 2. host and portN)r�r�r?r^r4r��errorr4s    r3r3zNodesManager.get_node�so���D��{�"��+�+�D�1���#�#�'�'�
�4�d�(K�L�L�
��#�#�'�'�	�2�2��I�I�#�
�
r5c��||_yr>)r�)rr�s  r3r�z#NodesManager.update_moved_exception
s
�� )��r5c��|j}|j|j|j��}|�|jt
urJt
|_n>t
|j|jt
�}||j|j<||j|jvr�|j|jd}t|_|j|jj|�|j|jj|�||j|jd<|j|k(r)||_d|_y|g|j|j<d|_y)z@
        Update the slot's node with the redirected one
        r2Nr)r�r3r,r-r�r7r�r?rOrE�slot_idr;rk�removerK)rr��redirected_node�old_primarys    r3�_update_moved_slotsz NodesManager._update_moved_slots
sE��
�!�!���-�-�Q�V�V�!�&�&�-�A���&��*�*�'�9�.5��+�*�!�&�&�!�&�&�'�B�O�5D�D���_�1�1�2��d�.�.�q�y�y�9�9��*�*�1�9�9�5�a�8�K�'.�K�#����Q�Y�Y�'�.�.�{�;�
���Q�Y�Y�'�.�.��?�-<�D���Q�Y�Y�'��*�� � �K�/�$3��!�!%���,;�*;�D���Q�Y�Y�'� $��r5c��|jr1|j5|jr|j�ddd�|jj	|��t|j|�dk(rt
d|�d|j�d���|durO|j|dj}|jj|t|j|��}nX|�$|tk(st|j|�dk(rd}n/tjdt|j|�dz
�}|j||S#1swY��xYw)z9
        Gets a node that servers this hash slot
        NrrCz5" not covered by the cluster. "require_full_coverage=�"TrY)r�rr�rEr^rjr"r�rOr�r�r7r��randint)rrarr��primary_namerHs      r3rlzNodesManager.get_node_from_slot4sX��� � ����
/��(�(��,�,�.�
/�������%�-��T�5E�5E�d�5K�1L�PQ�1Q�%����*�*.�*E�*E�)F�a�I��
�
��%��+�+�D�1�!�4�9�9�L��.�.�?�?��c�$�"2�"2�4�"8�9��H�
���g�%��4�#�#�D�)�*�a�/��H��~�~�a��T�-=�-=�d�-C�)D�q�)H�I�H�����%�h�/�/�9
/�
/�s�E
�
Ec�z�|jj�D�cgc]}|j|k(r|��c}Scc}w)z�
        Get all nodes with the specified server type
        :param server_type: 'primary' or 'replica'
        :return: list of ClusterNode
        )r?rJr�)rr�rps   r3r6z%NodesManager.get_nodes_by_server_typeWsA���(�(�/�/�1�
�����;�.�
�
�	
��
s�8c�D�|D]}||j|j<�y)zK
        Populate all startup nodes and filters out any duplicates
        N)r�rO)rrg�ns   r3r�z#NodesManager.populate_startup_nodescs'���	+�A�)*�D���q�v�v�&�	+r5c�:�tdt�D]}||vs�yy)NrFT)rir)rrEros   r3�check_slots_coveragez!NodesManager.check_slots_coveragejs+���q�2�3�	�A���#��	�r5c��|D]G}|j��|jd|j|jd�|j��|_�Iy)zV
        This function will create a redis connection to all nodes in :nodes:
        Nr2r1)r%�create_redis_noder,r-r�)rrgrps   r3r0z%NodesManager.create_redis_connectionsrsT���	�D��$�$�,�(>��(>�(>�)�������)�6:�6L�6L�)��%�	r5c��|jr=|jd|i�|jd|i�ttdi|����}|Std||d�|��}|S)Nr,r-)r8r2r1)r�r�r
r)rr,r-r�rGs     r3r�zNodesManager.create_redis_node|s]���=�=��M�M�6�4�.�)��M�M�6�4�.�)��n�&>�v�&>�?�A����5�4�d�5�f�5�A��r5c��t||�}|j|�}|�6|jj|�}|�|j�
t	|||�}|Sr>)r4r^r?r%r�)rr,r-�role�tmp_nodes_cacherDrTs       r3�_get_or_create_cluster_nodez(NodesManager._get_or_create_cluster_node�sa��!�$��-�	�%�)�)�)�4�����*�*�.�.�y�9�K��"�k�&B�&B�&J�)�$��d�;���r5c
�	�tjd�|j�i}i}g}d}d}|j}|jj�D�]�}	|jr
|j}notj|�}	|	jddd��|j|j|jfi|	��}||j|j_t|j�j!d��durt#d��t%|j'd��}
d}t5|
�dk(rDt5|
ddd�dk(r-t5|j�dk(r|j|
ddd<|
D�]�}|d}t%|d�}|dk(r|j}t7|d�}|j9||t:|�}|||j<t=t7|d�t7|d�dz�D�]}||vr�g||<||j?|�t=dt5|��D�cgc]}||��	}}|D]P}t%|d�}|d}|j9||t@|�}||j?|�|||j<�R��||d}|j|jk7s��|j?|j�d|j�d|���t5|�dkDs��t#ddjC|��������|jE|�}|s���n|st#d��|jGtI|j���|s+|jJrt#dt5|��dtL�d���||_'||_(|jSt:�d|_*|jVr||_d|_,y#t(t*f$r<}|j,}tj/d	|j�d
|���Yd}~���d}~wt0$rI}tj/d�|j-�}
d
|
vsd|
vrYd}~��t#d|�d|
����d}~wt2$r0}|j-�}
t#d|j�d|
����d}~wwxYwcc}w) z�
        Initializes the nodes cache, slots cache and redis connections.
        :startup_nodes:
            Responsible for discovering other nodes in the cluster
        z/Initializing the nodes' topology of the clusterFTr�)rwrx�cluster_enabledz(Cluster mode is not enabled on this noder�zQAn exception occurred while trying to initialize the cluster using the seed node z:
Nz6ReseponseError sending "cluster slots" to redis serverr�r�z7ERROR sending "cluster slots" command to redis server: z	. error: z6ERROR sending "cluster slots" command to redis server rYrrhrVr[z vs z
 on slot: r�z6startup_nodes could not agree on a valid slots cache: z, zORedis Cluster cannot be connected. Please provide at least one reachable node. z9All slots are not covered after query all startup_nodes. z of z covered...)-r�r�r�r�r�rJr%r�deepcopyr�r�r,r-rO�boolrPr^rr+r�rr#r�r�r!�	Exceptionrjr�r�r7rirkr;�joinr�r0r�r�rr?rEr6rKr�r�)rr��	tmp_slots�
disagreements�startup_nodes_reachable�
fully_coveredr��startup_noderG�copy_kwargs�
cluster_slotsr��msgr�ra�primary_noder,r-rTro�j�
replica_nodes�replica_node�target_replica_node�tmp_slots                         r3r�zNodesManager.initialize�s��	�	�	�C�D��
�
�����	��
�"'���
��'�'�� �.�.�5�5�7�p	�L�-
��0�0�$�5�5�A�#'�-�-��"7�K��&�&�D�g�'V�W�.��.�.�$�)�)�<�+<�+<��@K��A�NO�D�&�&�|�'8�'8�9�J��������%6�7�8�E�A�/�B���!-�Q�->�->��-O� P�
�*.�'�J�M�"�a�'��
�a�(��+�A�.�/�1�4���*�*�+�q�0�)5�):�):�
�a� ��#�A�&�%�,
"��#�A�w��#�L��O�4���2�:�'�,�,�D��<��?�+��"�>�>��$�����5@��� 0� 0�1��s�4��7�|�S��a��\�A�-=�>�"�A��	�)�')�	�!��!�!��+�+�K�8�:?��3�t�9�:M�(N�Q��a��(N�
�(N�,9�4�L�#/��Q��#@�D�#/��?�D�26�2R�2R� $�d�G�_�3�/�&�a�L�/�/�0C�D�!4�,� 3� 8� 8��4�$-�Q�<��?��#�=�=�K�,<�,<�<�)�0�0�#+�=�=�/��k�6F�6F�5G�z�RS�QT� U�� #�=�1�A�5�&;�'4�48�I�I�m�4L�3M�%O�'"�!"�9"�,
"�\!�5�5�i�@�M���ap	�d'�'�'��
�	
�%�%�d�?�+A�+A�+C�&D�E���!<�!<�(�K��y�>�"�$�'?�&@�A���
�+���$��� �9�9�'�B�1�E����&�&�!0�D�� $����u$�\�2�
��i�i���
�
��$�)�)�*�#�c�U�4��
�� �
��
�
�V�W��)�)�+�� �G�+�|�w�/F��/�#�#/�.�	�'��D�����
��)�)�+��+��*�/�/�0�	�'��D����
��L)Os=�CO'�R<
�'R9�61P-�-R9�9-Q=�,Q=�=R9�	+R4�4R9c��d|_|jj�D])}|js�|jj	��+yr>)rKr?rJr%rr(s  r3rzNodesManager.close3sC�� ����$�$�+�+�-�	.�D��$�$��%�%�+�+�-�	.r5c�X�	|jj�y#t$rYywxYwr>)r�r�r�rs r3r�zNodesManager.reset9s+��	��#�#�)�)�+���	��	�s��	)�))FFNTr�)FN)r�r�r�rr3r�r�rlr6r�r�r0r�r�r�rr�r1r5r3rr�sZ���#�
�"�
�2�**�%%�N!0�F

�+����
�\%�|.�r5rc�D��eZdZdZd�fd�	Zdd�Zd�Zd�Zd�Zd�Z	�xZ
S)	rVz�
    Wrapper for PubSub class.

    IMPORTANT: before using ClusterPubSub, read about the known limitations
    with pubsub in Cluster mode and learn how to workaround them:
    https://redis-py-cluster.readthedocs.io/en/stable/pubsub.html
    c����d|_|j||||�|j�dn$|j|j�j}||_t�|�di|�||jd���y)a*
        When a pubsub instance is created without specifying a node, a single
        node will be transparently chosen for the pubsub connection on the
        first command execution. The node will be determined by:
         1. Hashing the channel name in the request to find its keyslot
         2. Selecting a node that handles the keyslot: If read_from_replicas is
            set to true, a replica can be selected.

        :type redis_cluster: RedisCluster
        :type node: ClusterNode
        :type host: str
        :type port: int
        N)r8rr1)rp�set_pubsub_noder1r8�cluster�superrr)r�
redis_clusterrpr,r-r�r8rs       �r3rzClusterPubSub.__init__Js|�����	����]�D�$��=��y�y� �
��3�3�D�I�I�>�N�N�	�
%���
���	
��	
�&5�}�?T�?T�	
r5c��|�2|j|||j|j�|}||_y|�3|�1|j||��}|j||||�|}||_yt	||g�durtd��d}||_y)aN
        The pubsub node will be set according to the passed node, host and port
        When none of the node, host, or port are specified - the node is set
        to None and will be determined by the keyslot of the channel in the
        first command to be executed.
        RedisClusterException will be thrown if the passed node does not exist
        in the cluster.
        If host is passed without port, or vice versa, a DataError will be
        thrown.
        :type cluster: RedisCluster
        :type node: ClusterNode
        :type host: str
        :type port: int
        Nr2Tz6Passing a host requires passing a port, and vice versa)�_raise_on_invalid_noder,r-r3�anyrrp)rrrpr,r-�pubsub_nodes      r3rzClusterPubSub.set_pubsub_nodeds������'�'���t�y�y�$�)�)�L��K� ��	��
�$�"2��#�#��D�#�9�D��'�'���t�T�B��K� ��	��$���
�$�
&��W�X�X��K���	r5c��|jS)zJ
        Get the node that is being used as the pubsub connection
        )rprs r3�get_pubsub_nodezClusterPubSub.get_pubsub_node�s���y�y�r5c�d�|�|j|j���td|�d|�d���y)zl
        Raise a RedisClusterException if the node is None or doesn't exist in
        the cluster.
        NrNzNode r0z doesn't exist in the cluster)r3rOr)rr
rpr,r-s     r3rz$ClusterPubSub._raise_on_invalid_node�sF��
�<�=�1�1�D�I�I�1�F�N�'���v�Q�t�f�$A�B��
�Or5c��|j��|j��t|�dkDr[|d}|jj	|�}|jj
j
||jj�}n|jj�}||_	|jj|�}|j|_|jjd|j�|_|jj|j�|j}|j||j g|���y)z�
        Execute a publish/subscribe command.

        Taken code from redis-py and tweak to make it work within a cluster.
        NrYrW)r7r8rjrrDrrlrr@rpr1r9r\�register_connect_callbackr�_executer-)rr;r�rNrarpr%r7s        r3r�zClusterPubSub.execute_command�s���?�?�"��#�#�+��t�9�q�=�#�1�g�G��<�<�/�/��8�D��<�<�5�5�H�H��d�l�l�=�=��D�
 �<�<�7�7�9�D� ��	�#'�<�<�#D�#D�T�#J� �'7�'G�'G��$�"�2�2�A�A��$�/�/��D�O�

�O�O�5�5�d�o�o�F��_�_�
���
�
�j�*�"9�"9�A�D�Ar5c�H�|j�|jjSy)zH
        Get the Redis connection of the pubsub connected node.
        N)rpr%rs r3r1z"ClusterPubSub.get_redis_connection�s#���9�9� ��9�9�-�-�-�!r5r�)r�r�r�r�rrrrr�r1�
__classcell__�rs@r3rVrVAs)����
�4 �B��!B�F.r5rVc����eZdZdZeeeeefZ								dd�Z
d�Zd�Zd�Z
d�Zd�Zd�Zd	�Zd
�Zd�Zd�Zd
�Zdd�Zd�Z	dd�Z	d�fd�	Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z d�Z!d�Z"d�Z#d�Z$�xZ%S) rZz8
    Support for Redis pipeline
    in cluster mode
    c
��g|_||_||_d|_|xs$|jj
j
�|_|r|ng|_||_	|jjj
�|_||_||_
d|_||_t!|
j#dd�|
j#dd�|
j#dd��|_|	�t'j(�}	|	|_y)	riFrrxr�ryr�rwN)�
command_stackrr�refresh_table_asaprr�rrr�rr�rr
rr	r
rr^rrr&r)rrrrr
r�rrr
rYr�s           r3rzClusterPipeline.__init__�s��� ���*���.���"'����F���� ?� ?� D� D� F�	
��/<�]����"4���!�^�^�9�9�>�>�@���*D��'�,H��)�$%��!�"4�����J�J�z�7�+��J�J�(�(�3��J�J�)�5�1�
���
�<��>�>�#�D���
r5c�.�t|�j�S�ri)r�r�rs r3r�zClusterPipeline.__repr__�s���t�*�%�%�&�'r5c��|Srr1rs r3rzClusterPipeline.__enter__�s���r5c�$�|j�y�riN)r�rs    r3rzClusterPipeline.__exit__�s���
�
�r5c�D�	|j�y#t$rYywxYwr>)r�r�rs r3r"zClusterPipeline.__del__�s"��	��J�J�L���	��	�s��	�c�,�t|j�Sr)rjrrs r3�__len__zClusterPipeline.__len__s���4�%�%�&�&r5c��y)z@Pipeline instances should  always evaluate to True on Python 2.7Tr1rs r3�__nonzero__zClusterPipeline.__nonzero__	���r5c��y)z?Pipeline instances should  always evaluate to True on Python 3+Tr1rs r3�__bool__zClusterPipeline.__bool__
r&r5c�&�|j|i|��S)z?
        Wrapper function for pipeline_execute_command
        )�pipeline_execute_command�rr;r�s   r3r�zClusterPipeline.execute_commands��-�t�,�,�d�=�f�=�=r5c	�x�|jjt||t|j���|S)zN
        Appends the executed command to the pipeline's command stack
        )rrk�PipelineCommandrj�rr;r<s   r3r*z(ClusterPipeline.pipeline_execute_commands6��	
���!�!��D�'�3�t�/A�/A�+B�C�	
��r5c��|D]J}|j}t|t�s� |j||jdz|j
�|�y)z8
        Raise the first exception on the stack
        rYN)�resultr�r��annotate_exception�positionr;)r�stack�crGs    r3�raise_first_errorz!ClusterPipeline.raise_first_error sI���	�A����A��!�Y�'��'�'��1�:�:��>�1�6�6�B���		r5c��djtt|��}d|�d|�d|jd��}|f|jddz|_y)zS
        Provides extra context to the exception prior to it being handled
        riz
Command # z (z) of pipeline caused error: rrYN)r��mapr*r;)rr��numberr@�cmdr�s      r3r1z"ClusterPipeline.annotate_exception*s_���h�h�s�8�W�-�.������3�%�(�&�^�^�A�.�/�
1�	���)�.�.���"4�4�	�r5c��|j}	|j||�|j�S#|j�wxYw)zB
        Execute all the commands in the current pipeline
        )r�send_cluster_commandsr�)r�raise_on_errorr3s   r3�executezClusterPipeline.execute5s7���"�"��	��-�-�e�^�D��J�J�L��D�J�J�L�s	�0�Ac�L�g|_t�|_d|_d|_y)z/
        Reset back to empty pipeline.
        FN)r�set�scripts�watching�explicit_transactionrs r3r�zClusterPipeline.reset?s&�� ����u��� ��
�$)��!r5c��|sgStd|j�D]}	|j|||��cStd��#t$rY�1wxYw)a
        Wrapper for CLUSTERDOWN error handling.

        If the cluster reports it is down it is assumed that:
         - connection_pool was disconnected
         - connection_pool was reseted
         - refereh_table_asap set to True

        It will try the number of times specified by
        the config option "self.cluster_error_retry_attempts"
        which defaults to 3 unless manually configured.

        If it reaches the number of times, the command will
        raises ClusterDownException.
        r)r<�allow_redirectionsz0CLUSTERDOWN error. Unable to rebuild the cluster)rir�_send_cluster_commandsr)rr3r<rDr�s     r3r;z%ClusterPipeline.send_cluster_commands_sr��$��I��q�$�;�;�<�
	�A�	
��2�2��#1�'9�3���
	��Q�R�R��$�
��
�s�A�	A
�A
c���t|d���}i}|D�]}|jjdd�}|r#|j|�s|j	|�}n7|j
|jd|i�}|std|j�d���t|�dkDrtd	|j����|d
}	|	j}
|
|vrK|j|	�}t||j�}t|j|j|�||
<||
j|���|j!�}
|
D]}|j#��|
D]}|j%��|j!�D]'}|jj'|j(��)td�|D�d���}|r�|r�t*j-d
|dj�dt/|dj0�j2�dt5|dj0����|xj6dz
c_|j9�r|j:j=�|D]+}	t?�|��|ji|j��|_�-g}t|d���D]t}|jd
|jDvr<|jD|jd
|j0fi|j��|_|j|j0��v|r|jG|�|S#tB$r}||_Yd}~��d}~wwxYw)z�
        Send a bunch of cluster commands to the redis cluster.

        `allow_redirections` If the pipeline should follow
        `ASK` & `MOVED` responses automatically. If set
        to false it will raise RedisClusterException.
        c��|jSr>�r2�rms r3r�z8ClusterPipeline._send_cluster_commands.<locals>.<lambda>�s
��a�j�j�r5)rFr�N�	node_flagr�r�rYzToo many targets for command rc3�hK�|]*}t|jtj�r|���,y�wr>)r�r0rZr�)�.0r4s  r3�	<genexpr>z9ClusterPipeline._send_cluster_commands.<locals>.<genexpr>�s,����
���a�h�h��(J�(J�K��
�s�02c��|jSr>rHrIs r3r�z8ClusterPipeline._send_cluster_commands.<locals>.<lambda>�s
��!�*�*�r5z7An exception occurred during pipeline execution. args: ���z	, error: ric��|jSr>rHrIs r3r�z8ClusterPipeline._send_cluster_commands.<locals>.<lambda>s
��Q�Z�Z�r5)$�sortedr<r�r�r�rnr;rrjrOr1r9�NodeCommandsr�r8rkrJ�write�readr�r7r�r�r�r0r�r_r	rprr�r	r�r r
r5)rr3r<rD�attemptrgr4r�r�rprDr:r7�
node_commandsr�r�rErs                 �r3rEz&ClusterPipeline._send_cluster_commands�s:�����$8�9����
�	'�A��Y�Y�]�]�>�4�@�N��d�&9�&9�.�&I�#�7�7��G��4�t�4�4�a�f�f�W��W��#�/�;�A�F�F�8�;�O����<� �1�$�+�.K�A�F�F�8�,T�U�U���?�D��	�	�I���%�!�6�6�t�<�
�+�J����?�
�#/��-�-�z�/I�/I�:�$��i� �
�)��#�#�A�&�9	'�L����
��	�A�
�G�G�I�	��	�A�
�F�F�H�	�*����	4�A�
���%�%�a�l�l�3�	4��
� �
�
%�

���)�&
�M�M�� ���)�)�*�+��w�r�{�1�1�2�;�;�<�A��w�r�{�)�)�*�+�-�
�
�%�%��*�%��)�)�+��"�"�-�-�/��
!��!� %�w�6����L�!�)�)�L�A�H�	
!�����#7�8�	&�A��v�v�a�y�D�;�;�;�E�4�:�:�1�6�6�!�9�E��H�H�� !�	�	����
�O�O�A�H�H�%�	&���"�"�5�)����!"�!� �A�H�H��!�s�$(L*�*	M�3L?�?Mc��|std��y)riz4ASK & MOVED redirection not allowed in this pipelineN�r)rrDs  r3�_fail_on_redirectz!ClusterPipeline._fail_on_redirects��!�'�F��
�"r5c�(�|jdg|���S)N�EXISTS)r�)rrs  r3�existszClusterPipeline.exists$s��#�t�#�#�H�4�t�4�4r5c��td��)riz method eval() is not implementedrXrs r3�evalzClusterPipeline.eval's��#�$F�G�Gr5c��td��)riz!method multi() is not implementedrXrs r3�multizClusterPipeline.multi+���#�$G�H�Hr5c��td��)riz5method immediate_execute_command() is not implementedrXr.s   r3�immediate_execute_commandz)ClusterPipeline.immediate_execute_command/s��#�C�
�	
r5c��td��)riz0method _execute_transaction() is not implementedrXr+s   r3�_execute_transactionz$ClusterPipeline._execute_transaction5s��#�$V�W�Wr5c��td��)riz(method load_scripts() is not implementedrXrs r3�load_scriptszClusterPipeline.load_scripts9s��#�$N�O�Or5c��td��)riz!method watch() is not implementedrX�r�namess  r3�watchzClusterPipeline.watch=rar5c��td��)riz#method unwatch() is not implementedrXrs r3�unwatchzClusterPipeline.unwatchAs��#�$I�J�Jr5c��td��)riz4method script_load_for_pipeline() is not implementedrXr+s   r3�script_load_for_pipelinez(ClusterPipeline.script_load_for_pipelineEs��#�B�
�	
r5c�^�t|�dk7rtd��|jd|d�S)z7
        "Delete a key specified by ``names``"
        rYz=deleting multiple keys is not implemented in pipeline command�DELr)rjrr�ris  r3�deletezClusterPipeline.deleteKs8���u�:��?�'�R��
��#�#�E�5��8�4�4r5)NNNFr�r�N)T)TT)&r�r�r�r�rr#rrr$r�rr�rrr"r#r%r(r�r*r5r1r=r�r;rErYr\r^r`rcrergrkrmrorrrrs@r3rZrZ�s�����	��������#'�� �%&��
�#�J(����'���>���	5��*�B>B�#S�L>B�W�r�5�H�I�
�X�P�I�K�
�	5r5rZrO.c����fd�}|S)zi
    Prints error because some pipelined commands should
    be blocked when running in cluster-mode
    c�"��td��d���)Nz"ERROR: Calling pipelined function z1 is blocked when running redis in cluster mode...rX)r;r�rOs  �r3�innerz%block_pipeline_command.<locals>.inner]s!���#�0���74�
5�
�	
r5r1)rOrus` r3�block_pipeline_commandrvWs���
��Lr5)E�BGREWRITEAOFr��BITOP�
BRPOPLPUSHr�r�r�r��CLIENTr�r�r�r��CONFIGr��ECHOryr�r�r�r�r��MGETzMGET NONATOMIC�MOVE�MSETzMSET NONATOMIC�MSETNX�PFCOUNT�PFMERGEr��PUBLISHr�r�r��RENAME�RENAMENX�	RPOPLPUSHr�r�r�r�zSCRIPT KILLr��SCRIPT�SDIFF�
SDIFFSTOREz SENTINEL GET MASTER ADDR BY NAMEzSENTINEL MASTERzSENTINEL MASTERSzSENTINEL MONITORzSENTINEL REMOVEzSENTINEL SENTINELSzSENTINEL SETzSENTINEL SLAVES�SENTINELr��SINTER�SINTERSTORE�SLAVEOFr�r�r��SLOWLOG�SMOVE�SORT�SUNION�SUNIONSTOREr�rir�c��eZdZdZdd�Zy)r-riNc�`�||_|�i}||_||_d|_d|_d|_y)NF)r;r<r2r0rpr�)rr;r<r2s    r3rzPipelineCommand.__init__�s6����	��?��G���� ��
������	���r5r�)r�r�r�r�rr1r5r3r-r-�s
���r5r-c�(�eZdZdZd�Zd�Zd�Zd�Zy)rRric�<�||_||_||_g|_yr )r�r8r7�commands)rr�r8r7s    r3rzNodeCommands.__init__�s ��,���.���$�����
r5c�:�|jj|�yr )r�rk)rr4s  r3rkzNodeCommands.append�s���
�
���Q�r5c� �|j}|j}|D]	}d|_�	|j|j	|D�cgc]}|j
��c}��ycc}w#ttf$r}|D]	}||_�Yd}~yd}~wwxYw)z=
        Code borrowed from Redis so it can be fixed
        N)r7r�r0�send_packed_command�
pack_commandsr;rr#)rr7r�r4r�s     r3rSzNodeCommands.write�s����_�_�
��=�=���	�A��A�H�	�
	��*�*��(�(�(�)C�Q�!�&�&�)C�D�
��)C����.�	��
�����
��	�s)�A&�A!�A&�!A&�&B
�5B�B
c�p�|j}|jD]@}|j��	|j||jdfi|j
��|_�By#ttf$r#}|jD]	}||_�Yd}~yd}~wt$rtj�d|_Y��wxYw)riNrrY)r7r�r0r�r;r<rr#r �sys�exc_info)rr7r4r�s    r3rTzNodeCommands.read�s����_�_�
����	1�A�(�x�x��1�2�t�2�2�:�q�v�v�a�y�V�A�I�I�V�A�H�-	1��.(��6��!�]�]�%��#$���%���!�1�"�|�|�~�a�0�A�H�1�s�0A�B5�,B
�
(B5�4B5N)r�r�r�r�rrkrSrTr1r5r3rRrR�s���� ��,1r5rR)Yr�loggingr�r�r�rr��collectionsr�typingrrrr�redis.clientrr	r
r�redis.commandsrr
r�redis.connectionrrrr�	redis.crcrr�redis.exceptionsrrrrrrrrrrrr r!r"r#r$�
redis.lockr&�redis.utilsr'r(r)r*r+�	getLoggerr�r�r_r�r4r9rHrRrerrr7r;r�r�r�r�r�r�r�r�r�rrVrZrv�PIPELINE_BLOCKED_COMMANDSr@�replace�lowerr�r-rRr1r5r3�<module>r�s�����
�
�
���#�-�-�G�G�N�N�N�N�8������$����g����!�����3��3����
��

����	�%��S��/�4��S��>�
)�*��(�(��
��
����@(��
��M��EK�EK�Ph&�'�)=�h&�V*�*�8$�$�&c�c�L|.�F�|.�~T5�l�T5�n����#�s�(�);�� F��N)�G�G��o�o�c�3�'�-�-�/�G��O�W�&<�W�&E�F�G���C1�C1r5

Youez - 2016 - github.com/yon3zu
LinuXploit