HEX
Server: LiteSpeed
System: Linux kapuas.iixcp.rumahweb.net 5.14.0-427.42.1.el9_4.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Nov 1 14:58:02 EDT 2024 x86_64
User: mirz4654 (1666)
PHP: 8.1.33
Disabled: system,exec,escapeshellarg,escapeshellcmd,passthru,proc_close,proc_get_status,proc_nice,proc_open,proc_terminate,shell_exec,popen,pclose,dl,pfsockopen,leak,apache_child_terminate,posix_kill,posix_mkfifo,posix_setsid,posix_setuid,posix_setpgid,ini_alter,show_source,define_syslog_variables,symlink,syslog,openlog,openlog,closelog,ocinumcols,listen,chgrp,apache_note,apache_setenv,debugger_on,debugger_off,ftp_exec,dll,ftp,myshellexec,socket_bind,mail,posix_getwpuid
Upload Files
File: //lib/python3.9/site-packages/redis/__pycache__/cluster.cpython-39.pyc
a

��b�H�@s�ddlZddlZddlZddlZddlZddlZddlZddlmZddl	m
Z
mZmZm
Z
ddlmZmZmZmZddlmZmZddlmZmZmZmZddlmZmZddlmZm 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	l.m/Z/dd
l0m1Z1m2Z2m3Z3m4Z4m5Z5e�6e7�Z8e9e:e9d�dd
�Z;dd�Z<dd�Z=dd�Z>e
e
ee
e:e:fee9e
ffd�dd�Z?dd�Z@dZAdZBdZCdZDdZEeFgd��ZGdd �ZHGd!d"�d"e�ZIGd#d$�d$�ZJGd%d&�d&eJe�ZKGd'd(�d(�ZLGd)d*�d*�ZMGd+d,�d,�ZNGd-d.�d.e�ZOGd/d0�d0eK�ZPe9ed1e
fd2�d3d4�ZQd5ZReRD]&ZSeS�Td6d7��U�ZSeVePeSeQeS���q@Gd8d9�d9�ZWGd:d;�d;�ZXdS)<�N)�OrderedDict)�Any�Callable�Dict�Tuple)�CaseInsensitiveDict�PubSub�Redis�
parse_scan)�CommandsParser�RedisClusterCommands)�ConnectionPool�
DefaultParser�Encoder�	parse_url)�REDIS_CLUSTER_HASH_SLOTS�key_slot)�AskError�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�returncCs|�d|��S)N�:��r)r*r-r-�1/usr/lib/python3.9/site-packages/redis/cluster.py�
get_node_name,sr0cOs|jp|jj|dfi|��S)Nr)�
connection�connection_pool�get_connection)�
redis_node�args�optionsr-r-r/r30s
��r3c	KsFi}g}|��D],\}}t|fi|��\}}|||<||7}q||fS�N)�itemsr
)	�command�resr6Zcursors�ret�	node_name�responseZcursor�rr-r-r/�parse_scan_result6s
r?c
Ksht�}|��D]B}|D]8\}}z|||7<WqtyL|||<Yq0qqdd�|��D�}|S)NcSsg|]\}}||f�qSr-r-)�.0�channelZnumsubr-r-r/�
<listcomp>J�z'parse_pubsub_numsub.<locals>.<listcomp>)r�values�KeyErrorr8)r9r:r6Znumsub_dZnumsub_tupsrAZ	numsubbedZ
ret_numsubr-r-r/�parse_pubsub_numsubAsrF)�respr6r+cs||�dd��ttttfd��fdd��i}|D]F}|dd�\}}}|dd�}�|��fdd�|D�d	�|||f<q0|S)
N�current_host�)r5r+cst|d�p�|dfS�Nr�)r(�r5)rHr-r/�
fix_serverSsz'parse_cluster_slots.<locals>.fix_server�csg|]}�|��qSr-r-)r@�replica)rMr-r/rB\rCz'parse_cluster_slots.<locals>.<listcomp>)�primary�replicas)�getrr�str)rGr6�slots�slot�start�endrPrQr-)rHrMr/�parse_cluster_slotsNs�rXc	Ks�g}|D]�}ggd�}tdt|d�d�D]*}|d�|d||d|df�q*|d}|D]@}i}tdt|�d�D]}||d|||<qz|d�|�qb|�|�q|S)z(
    Parse CLUSTER SHARDS response.
    )rT�nodesrrK�rTrNrY)�range�len�append)	rGr6Zshards�xZshard�irY�nodeZ	dict_noder-r-r/�parse_cluster_shardsbs
(rarPrOzslot-id)�charsetZconnection_classr2Zclient_name�db�decode_responses�encoding�encoding_errors�errorsr)Zmax_connections�
nodes_flag�redis_connect_func�passwordr*ZretryZretry_on_timeoutZsocket_connect_timeoutZsocket_keepaliveZsocket_keepalive_optionsZsocket_timeoutZsslZssl_ca_certsZssl_ca_dataZssl_certfileZ
ssl_cert_reqsZssl_keyfileZssl_passwordZunix_socket_path�usernamer.)'ZBITCOUNTZBITPOS�EXISTSZGEODISTZGEOHASHZGEOPOSZ	GEORADIUSZGEORADIUSBYMEMBERZGETZGETBITZGETRANGEZHEXISTSZHGETZHGETALLZHKEYSZHLENZHMGETZHSTRLENZHVALS�KEYSZLINDEXZLLENZLRANGE�MGETZPTTL�	RANDOMKEYZSCARD�SDIFF�SINTERZ	SISMEMBERZSMEMBERSZSRANDMEMBERZSTRLEN�SUNIONZTTLZZCARDZZCOUNTZZRANGEZZSCOREcKsdd�|��D�}|S)z9
    Remove unsupported or disabled keys from kwargs
    cSs&i|]\}}|tvr|tvr||�qSr-)�REDIS_ALLOWED_KEYS�KWARGS_DISABLED_KEYS)r@�k�vr-r-r/�
<dictcomp>�s�z"cleanup_kwargs.<locals>.<dictcomp>)r8)�kwargs�connection_kwargsr-r-r/�cleanup_kwargs�s�rzc	@s&eZdZeejeeee	e
ed��ZdS)�
ClusterParser)ZASKZTRYAGAINZMOVED�CLUSTERDOWNZ	CROSSSLOT�
MASTERDOWNN)�__name__�
__module__�__qualname__r$rZEXCEPTION_CLASSESrr!rrrrr-r-r-r/r{�s��r{c@seZdZdZdZdZdZdZdZeeeeehZ	e
egd�e�egd�e�ed	ge�egd
�e��Z
gd�fZeed�Ze
ed
ge�edgdd��eddge�egd�dd��eddgdd��edgdd��edge�edgdd��edgdd��edgd d���
ZeeefZd!S)"�AbstractRedisCluster�Z	primariesrQ�all�randomzdefault-node)GzACL CATzACL DELUSERz
ACL DRYRUNzACL GENPASSzACL GETUSERzACL HELPzACL LISTzACL LOGzACL LOADzACL SAVEzACL SETUSERz	ACL USERSz
ACL WHOAMIZAUTH�CLIENT LIST�CLIENT SETNAME�CLIENT GETNAME�
CONFIG SET�CONFIG REWRITE�CONFIG RESETSTAT�TIME�PUBSUB CHANNELS�
PUBSUB NUMPAT�
PUBSUB NUMSUB�PING�INFO�SHUTDOWNrm�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 KEYSLOTZCOMMANDz
COMMAND COUNTzCOMMAND LISTzCOMMAND GETKEYS�
CONFIG GET�DEBUGror�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�cCstt|����Sr7)�sum�listrD�r9r:r-r-r/�<lambda>�rCzAbstractRedisCluster.<lambda>rmr�)r�r�r�r�r�r�r�r�r�r�r�cCst|t�rt|���S|Sr7)�
isinstance�dictr�rDr�r-r-r/r��rCr�r�cCst|t�rt|���S|Sr7)r�r�r�rDr�r-r-r/r��rCr�cCst|���dkrdSdSrJ)r�rDr�r-r-r/r��rCr�r�cCst|�����Sr7)r�rD�popr�r-r-r/r��rCr�cCsdd�t|���D�S)NcSsg|]}t|��qSr-)r�)r@rur-r-r/rB�rCz1AbstractRedisCluster.<lambda>.<locals>.<listcomp>)�ziprDr�r-r-r/r��rCr�cCst|���Sr7)r�rDr�r-r-r/r��rCN)r~rr��RedisClusterRequestTTL�	PRIMARIES�REPLICAS�	ALL_NODES�RANDOM�DEFAULT_NODE�
NODE_FLAGSr$r%�SLOT_ID�
COMMAND_FLAGS�SEARCH_COMMANDSrXra�#CLUSTER_COMMANDS_RESPONSE_CALLBACKSrFr&r?�RESULT_CALLBACKSrr r�ERRORS_ALLOW_RETRYr-r-r-r/r��slI�L
�
��k�%�

�
��
�

�
��'r�c@s6eZdZedd��ZdNdd	�Zd
d�Zdd
�Zdd�Zdd�Z	dd�Z
dd�ZdOdd�Zdd�Z
dd�Zdd�Zdd�ZdPd d!�Zd"d#�Zd$d%�ZdQd&d'�ZdRd(d)�ZdSd*d+�ZdTd.d/�Zd0d1�Zd2d3�Zd4d5�Zd6d7�Zd8d9�Zd:d;�Zd<d=�Zd>d?�Zd@dA�Z dBdC�Z!dDdE�Z"dFdG�Z#dHdI�Z$dJdK�Z%dLdM�Z&dS)U�RedisClustercKs|fd|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.

        �urlr-)�clsr�rxr-r-r/�from_url�s*zRedisCluster.from_urlN��rNF�
c	Ks�|durg}d|	vrtd��d}
|dur�d}
t|�}d|vrDtd��d|vr`|ddkr`td	��|	�|�|	�d
�}|	�d|�}|�t||��n6|dur�|dur�|�t||��nt|�dkr�td��t�d
|���|	�	dd�|_
|	�d|ji�tfi|	��}	t
|	�dd�|	�dd�|	�dd��|_||_|jj��|_|jj��|_||_d|_||_d|_tf||
|d�|	��|_t|jj�|_t|jj�|_t |�|_!t"�#�|_$dS)ag	
         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.
        :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)
        Nrcz4Argument '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 : rire�utf-8rf�strictrd)�
startup_nodesr��require_full_coverage)%rr�updaterRr]�ClusterNoder\�log�debugr��user_on_connect_func�
on_connectrzr�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�r�r�r�r�r�rxr�Zurl_optionsr-r-r/�__init__�sr:���

�	


����
zRedisCluster.__init__cCs|Sr7r-�r�r-r-r/�	__enter__bszRedisCluster.__enter__cCs|��dSr7��close�r��exc_type�	exc_value�	tracebackr-r-r/�__exit__eszRedisCluster.__exit__cCs|��dSr7r�r�r-r-r/�__del__hszRedisCluster.__del__c	Cs<|��D].}|jrz|jj��Wqty4Yq0qdSr7)�	get_nodes�redis_connectionr2�
disconnect�OSError�r�r`r-r-r/�disconnect_connection_poolsksz(RedisCluster.disconnect_connection_poolscCsR|�t�|��|jr:|�d�t|���dkr:td��|jdurN|�|�dS)z�
        Initialize the connection, authenticate and select a database and send
         READONLY if it is set during object initialization.
        r�ZOKzREADONLY command failedN)	Z
set_parserr{r�r��send_commandr(Z
read_responserr�)r�r1r-r-r/r�ts


zRedisCluster.on_connectcCsF|js@|j�$|js"|j�|g�Wd�n1s60Y|jSr7)r�r�r��create_redis_connectionsr�r-r-r/�get_redis_connection�s
,z!RedisCluster.get_redis_connectioncCs|j�|||�Sr7)r��get_node�r�r)r*r<r-r-r/r��szRedisCluster.get_nodecCs|j�t�Sr7)r��get_nodes_by_server_type�PRIMARYr�r-r-r/�
get_primaries�szRedisCluster.get_primariescCs|j�t�Sr7)r�r��REPLICAr�r-r-r/�get_replicas�szRedisCluster.get_replicascCst�t|jj����Sr7)r��choicer�r��nodes_cacherDr�r-r-r/�get_random_node�szRedisCluster.get_random_nodecCst|jj���Sr7)r�r�r�rDr�r-r-r/r��szRedisCluster.get_nodescCsn|�|�}|jj�|�}|dus,t|�dkr<td|�d���|rXt|jj|�dkrXdS|rbd}nd}||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.rZrK)�keyslotr��slots_cacherRr\r)r��keyrOrUZ
slot_cache�node_idxr-r-r/�get_node_from_key�s
zRedisCluster.get_node_from_keycCs|jjS)z0
        Get the cluster's default node
        )r��default_noder�r-r-r/�get_default_node�szRedisCluster.get_default_nodecCsD|dus|j|jd�dur(t�d�dS||j_t�d|���dS)z�
        Set the default node of the cluster.
        :param node: 'ClusterNode'
        :return True if the default node was set, else False
        N�r<zVThe requested node does not exist in the cluster, so the default node was not changed.Fz$Changed the default cluster node to T)r��namer��infor�rr�r-r-r/�set_default_node�s�zRedisCluster.set_default_nodecCs6|dur|��}|jdur,td|j�d���|j��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.
        Nz
Cluster Node z has no redis_connection)rr�rr	�monitor)r��target_noder-r-r/r�s	
�zRedisCluster.monitorcKst|f|||d�|��S)z~
        Allows passing a ClusterNode, or host&port, to get a pubsub instance
        connected to the specified node
        )r`r)r*)�
ClusterPubSub)r�r`r)r*rxr-r-r/�pubsub�szRedisCluster.pubsubcCsF|rtd��|rtd��t|j|j|jj|j|j|j|j|j	|j
d�	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)	r�r�r�r�r�r�r�r��lock)r�ClusterPipeliner�r�r�r�r�r�r�r�r�)r�Ztransaction�
shard_hintr-r-r/�pipeline�s	�zRedisCluster.pipeline皙�����?Tc	Cs"|durt}||||||||d�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.N)�timeout�sleep�blocking�blocking_timeout�thread_localr")r�r	rrrrZ
lock_classrr-r-r/r�s>�zRedisCluster.lockcCs||j|<dS)zSet a custom Response CallbackN)r�)r�r9�callbackr-r-r/�set_response_callbackFsz"RedisCluster.set_response_callbackcOs\|d��}t|�dkrR|d�d|d����|jvrR|d�d|d����}|�dd�}|durl|}n|j�|�}|r�t�d|�d|���||jjkr�|�	�gS||jj
kr�|��S||jjkr�|�
�S||jjkr�|��S||jjk�r�|jjgS||jjdv�r|jjgS|j|�}|j�||j�o8|tv�}t�d|�d	|���|gSdS)
NrrZ� rKrhzTarget node/s for z: zTarget for z: slot )�upperr\r�r�rRr�r�r�r�r�r�r�r�r�r�r�r�r�rr��determine_slot�get_node_from_slotr��
READ_COMMANDS)r�r5rxr9rhZcommand_flagrUr`r-r-r/�_determine_nodesJs6,



�zRedisCluster._determine_nodescCs"|jdkrdS|j|jdkSdS)NrF)r�r�r�r-r-r/�_should_reinitializedrs
z"RedisCluster._should_reinitializedcCs|j�|�}t|�S)z�
        Calculate keyslot for a given key.
        See Keys distribution model in https://redis.io/topics/cluster-spec
        )r��encoder)r�rrur-r-r/r|szRedisCluster.keyslotcGs|��j}|jj|g|�R�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.
        )rr�r�Zget_keys)r�r5Z
redis_connr-r-r/�_get_command_keys�s
zRedisCluster._get_command_keyscs|d}�j�|�tkr |dS|dvrxt|�dkrBtd|����|d}|dd|�}t|�dkrrt�dt�S|}n@�j|�}|dus�t|�dkr�|dvr�t�dt�Std	|����t|�dkr҈�	|d�S�fd
d�|D�}t|�dkr�t|�d���|�
�S)
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.
        rrK)ZEVAL�EVALSHArZzInvalid args in command: rNN)ZFCALLZFCALL_ROz�No way to dispatch this command to Redis Cluster. Missing key.
You can execute the command by specifying target nodes.
Command: csh|]}��|��qSr-)r)r@rr�r-r/�	<setcomp>�rCz.RedisCluster.determine_slot.<locals>.<setcomp>z) - all keys must map to the same key slot)r�rRr�r\rr�Z	randrangerr$rr�)r�r5r9Znum_actual_keysZ	eval_keys�keysrTr-r�r/r�s8
���zRedisCluster.determine_slotcCs|jS)z.
        Get the connections' encoder
        )r�r�r-r-r/�get_encoder�szRedisCluster.get_encodercCs|jjS)z9
        Get the connections' key-word arguments
        )r�ryr�r-r-r/�get_connection_kwargs�sz"RedisCluster.get_connection_kwargscCst|t�o||jvSr7)r�rSr�)r��target_nodesr-r-r/�_is_nodes_flag�szRedisCluster._is_nodes_flagcCsLt|t�r|}n8t|t�r"|g}n&t|t�r6|��}ntdt|�����|S)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�rD�	TypeError�type)r�r*rYr-r-r/�_parse_target_nodes�s



��z RedisCluster._parse_target_nodescOsd}d}|�dd�}|dur4|�|�s4|�|�}d}|r<dn|j}d}td|�D]�}zzi}	|s�|j|i|�d|i��}|s�td|�d	���|D]"}
|j|
g|�Ri|��|	|
j<q�|j	|d|	fi|��WSt
�y}z&t|�|jj
vr�|}n|�WYd}~qPd}~00qP|�dS)
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*TrKrrhz!No targets were found to execute z command on)r�r+r.r�r[r!r�_execute_commandr	�_process_result�
BaseExceptionr-r�r�)r�r5rxZtarget_nodes_specifiedr*Zpassed_targetsZretry_attempts�	exception�_r:r`�er-r-r/�execute_command�s@

����
� zRedisCluster.execute_commandc
Os�|d}d}d}d}d}d}	t|j�}
d}|
dk�r�|
d8}
�zx�z|rV|j|d�}n*|	r�|j|�}|j�||jox|tv�}d}	t�	d|�d|j
�d|j���|�|�}t
|g|�Ri|��}|r�|�d	�|j|d	fi|��d}|j|�|j||fi|��}
||jv�r&|j||
fi|��}
|
WW|du�rB|j�|�Sttf�y~}zt�t|���WYd}~�n(d}~0ttf�y�}zXt�t|��|du�r�|��|d7}|d
k�r�t�d�n|j���WYd}~�n�d}~0t�y\}zRt�d�|jd7_|���r6|j��d|_n|j� |�d
}	WYd}~�nJd}~0t!�y�t�d�|
|jdk�r�t�d�Y�n
t"�y�}z*t�d�t#|j$|j%d�}d
}WYd}~n�d}~0t&�y}z.t�d�t�d�|j��|�WYd}~n�d}~0t'�y\}z(|�(�}t�d|���|�WYd}~nJd}~0t)�y�}z(t�d�|�r�|��|�WYd}~n
d}~00W|du�r�|j�|�q*|du�r�|j�|�0q*t*d��dS)z9
        Send a command to a node in the cluster
        rNFrKrzExecuting command z on target node: rZASKING�g�?rTr!rZg�������?rr.rzResponseError: r1zTTL exhausted.)+�intr�r�rr�rr�r r�r��server_typer	r�r3r��parse_responser�r2�releaserrr2r-rr r��timer�
initializerr�r"�update_moved_exceptionr!rr0r)r*rr�__str__r1r)r�r
r5rxr9r4r1Z
redirect_addr�askingZmovedZttlZconnection_error_retry_counterrUr=r4�messager-r-r/r/.s�


����


��G
�


	









�
zRedisCluster._execute_commandcCsRz:|j� |jr|j��Wd�n1s.0YWntyLYn0dSr7)r�r�r��AttributeErrorr�r-r-r/r��s,zRedisCluster.closecKsF||jvr"|j|||fi|��St|�dkr>t|���dS|SdS)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>
        rKrN)r�r\r�rD)r�r9r:rxr-r-r/r0�s

zRedisCluster._process_resultcCst|||�dS)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�funcr-r-r/�load_external_module�sz!RedisCluster.load_external_module)Nr�NrNFr�FN)NNN)F)N)NNN)NN)NrTNNT)'r~rr��classmethodr�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrrrrr!r"rr$rr(r)r+r.r5r/r�r0rEr-r-r-r/r��sf
-�
	




�
J(
9?x	r�c@s.eZdZd
dd�Zdd�Zdd�Zdd	�ZdS)r�NcCs:|dkrt�|�}||_||_t||�|_||_||_dS)N�	localhost)�socket�
gethostbynamer)r*r0r	r8r�)r�r)r*r8r�r-r-r/r��s
zClusterNode.__init__cCs.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*r	r8r�r�r-r-r/�__repr__�s
�����zClusterNode.__repr__cCst|t�o|j|jkSr7)r�r�r	)r��objr-r-r/�__eq__�szClusterNode.__eq__cCs|jdur|j��dSr7)r�r�r�r-r-r/r��s
zClusterNode.__del__)NN)r~rr�r�rKrMr�r-r-r-r/r��s

	r�c@sBeZdZdZd
edd�dd�Zeeed�dd	�Zdd
�dd�ZdS)�LoadBalancerz$
    Round-Robin Load Balancing
    rN)�start_indexr+cCsi|_||_dSr7)�primary_to_idxrO)r�rOr-r-r/r��szLoadBalancer.__init__)rP�	list_sizer+cCs&|j�||j�}|d||j|<|S)NrK)rP�
setdefaultrO)r�rPrQZserver_indexr-r-r/�get_server_index�szLoadBalancer.get_server_index)r+cCs|j��dSr7)rP�clearr�r-r-r/�reset�szLoadBalancer.reset)r)	r~rr��__doc__r7r�rSrSrUr-r-r-r/rN�srNc@szeZdZddd�Zddd�Zdd�Zd	d
�Zddd�Zd
d�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�ZdS) r�FNcKsdi|_i|_i|_d|_|�|�||_||_d|_||_t	�|_
|durRt��}||_
|��dSr7)r�rr�r�populate_startup_nodesr��_require_full_coverage�_moved_exceptionryrN�read_load_balancerr�r#r�r<)r�r�r�r�rrxr-r-r/r��s
zNodesManager.__init__cCsP|r.|r.|dkrt�|�}|j�t||d��S|r>|j�|�St�d�dSdS)z�
        Get the requested node from the cluster's nodes.
        nodes.
        :return: ClusterNode if the node exists, else None
        rGr.zEget_node requires one of the following: 1. node name 2. host and portN)rHrIr�rRr0r��errorr�r-r-r/r�s
�zNodesManager.get_nodecCs
||_dSr7)rY)r�r2r-r-r/r=*sz#NodesManager.update_moved_exceptioncCs�|j}|j|j|jd�}|dur2|jturNt|_nt|j|jt�}||j|j<||j	|j
vr�|j	|j
d}t|_|j	|j
�|�|j	|j
�
|�||j	|j
d<|j|kr�||_n|g|j	|j
<d|_dS)z@
        Update the slot's node with the redirected one
        r.Nr)rYr�r)r*r8r�r�r�r	rZslot_idr�r]�remover)r�r4Zredirected_nodeZold_primaryr-r-r/�_update_moved_slots-s"

z NodesManager._update_moved_slotscCs�|jr:|j�|jr|��Wd�n1s00Y|j�|�dus\t|j|�dkrttd|�d|j�d���|dur�|j|dj}|j	�
|t|j|��}nB|dus�|tks�t|j|�dkr�d}nt�
dt|j|�d�}|j||S)z9
        Gets a node that servers this hash slot
        Nrrz5" not covered by the cluster. "require_full_coverage=�"TrK)rYr�r]rrRr\rrXr	rZrSr�r�Zrandint)r�rUr�r8Zprimary_namerr-r-r/rTs0&"������zNodesManager.get_node_from_slotcs�fdd�|j��D�S)z�
        Get all nodes with the specified server type
        :param server_type: 'primary' or 'replica'
        :return: list of ClusterNode
        csg|]}|j�kr|�qSr-�r8)r@r`r_r-r/rB}s
�z9NodesManager.get_nodes_by_server_type.<locals>.<listcomp>)r�rD)r�r8r-r_r/r�ws
�z%NodesManager.get_nodes_by_server_typecCs|D]}||j|j<qdS)zK
        Populate all startup nodes and filters out any duplicates
        N)r�r	)r�rY�nr-r-r/rW�sz#NodesManager.populate_startup_nodescCs"tdt�D]}||vr
dSq
dS)NrFT)r[r)r�rr_r-r-r/�check_slots_coverage�sz!NodesManager.check_slots_coveragecCs6|D],}|jdur|jf|j|jd�|j��|_qdS)zV
        This function will create a redis connection to all nodes in :nodes:
        Nr.)r��create_redis_noder)r*ry)r�rYr`r-r-r/r��s
��z%NodesManager.create_redis_connectionscKsP|jr8|�d|i�|�d|i�ttfi|��d�}ntf||d�|��}|S)Nr)r*)r2r.)r�r�r	r
)r�r)r*rxr>r-r-r/rb�szNodesManager.create_redis_nodecs$t�d�|��i}i}g}d}d}|j}|j��D�]l}z�|jrL|j}n@t�|�}	|	�	ddd��|j
|j|jfi|	��}||j|j
_t|���d��dur�td��t|�d��}
d}W�nttf�y}z6|j}t�d	|j
�d
|���WYd}~q6WYd}~n�d}~0t�y�}zTt�d�|��}
d
|
v�sJd|
v�rXWYd}~q6ntd|�d|
����WYd}~nLd}~0t�y�}z*|��}
td|j
�d|
����WYd}~n
d}~00t|
�dk�rt|
ddd�dk�rt|j�dk�r|j|
ddd<|
D�]z��d}|d}|dk�r8|j}t|d�}|�t||��}|du�rjt||t�}|||j
<tt�d�t�d�d�D]�}||v�r.g||<||� |��fdd�tdt���D�}|D]T}|d}|d}|�t||��}|du�rt||t!�}||� |�|||j
<�q�nZ||d}|j
|j
k�r�|� |j
�d|j
�d|���t|�dk�r�tdd�"|������q��q|�#|�}|r6�q�q6|�s�td��|�$t%|����|�s�|j&�r�tdt|��d t'�d!���||_(||_)|�*t�d|_+|�,|j(���d|_-dS)"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�)rdreZcluster_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 rKrrZrIcsg|]}�|�qSr-r-)r@�j�rUr-r/rBrCz+NodesManager.initialize.<locals>.<listcomp>rNz vs z
 on slot: r6z6startup_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�rUryr�rDr�r��deepcopyr�rbr)r*r	�boolr
rRrr(r5rr r>r2r�	Exceptionr\r7r0r�r�r[r]r��joinrar�r�rXrr�rr�rrWrY)r�Ztmp_nodes_cacheZ	tmp_slotsZ
disagreementsZstartup_nodes_reachableZ
fully_coveredrxZstartup_noder>Zcopy_kwargsZ
cluster_slotsr4�msgr@Zprimary_noder)r*r
r_Z
replica_nodesZreplica_nodeZtarget_replica_nodeZtmp_slotr-rdr/r<�s�

���
��� 
������
���



"
�
�����
����zNodesManager.initializecCs*d|_|j��D]}|jr|j��qdSr7)rr�rDr�r�r�r-r-r/r�EszNodesManager.closecCs&z|j��Wnty Yn0dSr7)rZrUr,r�r-r-r/rUKszNodesManager.reset)FFN)NNN)FN)r~rr�r�r�r=r]rr�rWrar�rbr<r�rUr-r-r-r/r��s"�

'
#

 r�csLeZdZdZd�fdd�	Zddd�Zdd�Zd	d
�Zdd�Zd
d�Z	�Z
S)rz�
    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
    NcsZd|_|�||||�|jdur$dn|�|j�j}||_t�jfi|�||jd���dS)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)r2r�)r`�set_pubsub_noder�r2�cluster�superr�r�)r��
redis_clusterr`r)r*rxr2�r�r-r/r�\s��
��zClusterPubSub.__init__cCs~|dur"|�|||j|j�|}nR|durV|durV|j||d�}|�||||�|}nt||g�durptd��nd}||_dS)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
        Nr.Tz6Passing a host requires passing a port, and vice versa)�_raise_on_invalid_noder)r*r��anyrr`)r�rkr`r)r*Zpubsub_noder-r-r/rjvs
zClusterPubSub.set_pubsub_nodecCs|jS)zJ
        Get the node that is being used as the pubsub connection
        )r`r�r-r-r/�get_pubsub_node�szClusterPubSub.get_pubsub_nodecCs4|dus|j|jd�dur0td|�d|�d���dS)zl
        Raise a RedisClusterException if the node is None or doesn't exist in
        the cluster.
        NrzNode r,z doesn't exist in the cluster)r�r	r)r�rmr`r)r*r-r-r/ro�s�z$ClusterPubSub._raise_on_invalid_nodecOs�|jdur�|jdurnt|�dkrJ|d}|j�|�}|jj�||jj�}n
|j��}||_	|j�
|�}|j|_|j�d|j�|_|j�
|j�|j}|j||jg|�R�dS)z�
        Execute a publish/subscribe command.

        Taken code from redis-py and tweak to make it work within a cluster.
        NrKr)r1r2r\rkrr�rr�r�r`r�r3rZregister_connect_callbackr�Z_executer�)r�r5rxrArUr`r�r1r-r-r/r5�s$


�
�zClusterPubSub.execute_commandcCs|jdur|jjSdS)zH
        Get the Redis connection of the pubsub connected node.
        N)r`r�r�r-r-r/r��s
z"ClusterPubSub.get_redis_connection)NNN)NNN)r~rr�rVr�rjrqror5r��
__classcell__r-r-rnr/rSs
!
#rcseZdZdZeeeeefZ	d=dd�Z
dd	�Zd
d�Zdd
�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd>dd �Zd!d"�Zd?d#d$�Zd@�fd%d&�	Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Z d5d6�Z!d7d8�Z"d9d:�Z#d;d<�Z$�Z%S)Arz8
    Support for Redis pipeline
    in cluster mode
    NFr6r�c
Ks�g|_||_||_d|_|p&|jj��|_|r2|ng|_||_	|jj
��|_||_||_
d|_||_t|
�dd�|
�dd�|
�dd��|_|	dur�t��}	|	|_dS)	rFrrer�rfr�rdN)�
command_stackr�r�Zrefresh_table_asapr�r�r�r�r�r�r�r�r�r�r�r�rrRr�r�r#r�)r�r�r�r�r�r�r�r�r�rrxr-r-r/r��s*�


�zClusterPipeline.__init__cCst|�j�S�r)r-r~r�r-r-r/rKszClusterPipeline.__repr__cCs|Srtr-r�r-r-r/r�	szClusterPipeline.__enter__cCs|��dS�rN)rUr�r-r-r/r�
szClusterPipeline.__exit__cCs$z|��WntyYn0dSr7)rUrgr�r-r-r/r�szClusterPipeline.__del__cCs
t|j�Srt)r\rsr�r-r-r/�__len__szClusterPipeline.__len__cCsdS)z@Pipeline instances should  always evaluate to True on Python 2.7Tr-r�r-r-r/�__nonzero__szClusterPipeline.__nonzero__cCsdS)z?Pipeline instances should  always evaluate to True on Python 3+Tr-r�r-r-r/�__bool__szClusterPipeline.__bool__cOs|j|i|��S)z?
        Wrapper function for pipeline_execute_command
        )�pipeline_execute_command�r�r5rxr-r-r/r5#szClusterPipeline.execute_commandcOs|j�t||t|j���|S)zN
        Appends the executed command to the pipeline's command stack
        )rsr]�PipelineCommandr\�r�r5r6r-r-r/ry)s�z(ClusterPipeline.pipeline_execute_commandcCs8|D].}|j}t|t�r|�||jd|j�|�qdS)z8
        Raise the first exception on the stack
        rKN)�resultr�rg�annotate_exception�positionr5)r��stack�cr>r-r-r/�raise_first_error2s

z!ClusterPipeline.raise_first_errorcCsFd�tt|��}d|�d|�d|jd��}|f|jdd�|_dS)zS
        Provides extra context to the exception prior to it being handled
        rz
Command # z (z) of pipeline caused error: rrKN)rh�mapr'r5)r�r2Znumberr9�cmdrir-r-r/r~<s��z"ClusterPipeline.annotate_exceptionTcCs,|j}z|�||�W|��S|��0dS)zB
        Execute all the commands in the current pipeline
        N)rs�send_cluster_commandsrU)r��raise_on_errorr�r-r-r/�executeGs�zClusterPipeline.executecCsg|_t�|_d|_d|_dS)z/
        Reset back to empty pipeline.
        FN)rs�setZscriptsZwatchingZexplicit_transactionr�r-r-r/rUQszClusterPipeline.resetc	CsP|sgStd|j�D].}z|j|||d�WSty@Yq0qtd��dS)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 clusterN)r[r��_send_cluster_commandsr)r�r�r�r�r3r-r-r/r�qs�z%ClusterPipeline.send_cluster_commandscst|dd�d�}i}|D]^}|j|j�}|dj}||vrh|�|d�}	t|	|j�}
t|	j|	j|
�||<||�	|�q|�
�}|D]}|��q�|D]}|��q�|�
�D]}|j�
|j�q�tdd�|D�dd�d�}|�r�|�r�t�d|d	j�d
t|d	j�j�dt|d	j����|jd7_|���r@|j��|D]P}zt�j|ji|j��|_Wn,t�y�}
z|
|_WYd
}
~
n
d
}
~
00�qDg}t|dd�d�D]F}|jd|jv�r�|j|jd|jfi|j��|_|�	|j��q�|�r|�|�|S)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.
        cSs|jSr7�r�r^r-r-r/r��rCz8ClusterPipeline._send_cluster_commands.<locals>.<lambda>)rrcss |]}t|jtj�r|VqdSr7)r�r}rr��r@r�r-r-r/�	<genexpr>�s�z9ClusterPipeline._send_cluster_commands.<locals>.<genexpr>cSs|jSr7r�r�r-r-r/r��rCz7An exception occurred during pipeline execution. args: ���z	, error: rrKNcSs|jSr7r�r�r-r-r/r�rC)�sortedr!r5r	r�r3�NodeCommandsr9r2r]rD�write�readr:r1r�r2r-r}r~rSr�r"r�r<rlr5r6rr�r�)r�r�r�r�ZattemptrYr�r`r<r4r1Z
node_commandsr`r4r=rnr-r/r��sn

�


������

 ��
z&ClusterPipeline._send_cluster_commandscCs|std��dS)rz4ASK & MOVED redirection not allowed in this pipelineN�r)r�r�r-r-r/�_fail_on_redirect$s�z!ClusterPipeline._fail_on_redirectcGs|jdg|�R�S)Nrl)r5)r�r'r-r-r/�exists+szClusterPipeline.existscCstd��dS)rz method eval() is not implementedNr�r�r-r-r/�eval.szClusterPipeline.evalcCstd��dS)rz!method multi() is not implementedNr�r�r-r-r/�multi2szClusterPipeline.multicOstd��dS)rz5method immediate_execute_command() is not implementedNr�r|r-r-r/�immediate_execute_command6s�z)ClusterPipeline.immediate_execute_commandcOstd��dS)rz0method _execute_transaction() is not implementedNr�rzr-r-r/�_execute_transaction<sz$ClusterPipeline._execute_transactioncCstd��dS)rz(method load_scripts() is not implementedNr�r�r-r-r/�load_scripts@szClusterPipeline.load_scriptscGstd��dS)rz!method watch() is not implementedNr��r��namesr-r-r/�watchDszClusterPipeline.watchcCstd��dS)rz#method unwatch() is not implementedNr�r�r-r-r/�unwatchHszClusterPipeline.unwatchcOstd��dS)rz4method script_load_for_pipeline() is not implementedNr�rzr-r-r/�script_load_for_pipelineLs�z(ClusterPipeline.script_load_for_pipelinecGs$t|�dkrtd��|�d|d�S)z7
        "Delete a key specified by ``names``"
        rKz=deleting multiple keys is not implemented in pipeline commandZDELr)r\rr5r�r-r-r/�deleteRs
�zClusterPipeline.delete)NNNFr6r�N)T)TT)TT)&r~rr�rVrr rrr!r�r�rKr�r�r�rvrwrxr5ryr�r~r�rUr�r�r�r�r�r�r�r�r�r�r�r�r�rrr-r-rnr/r�sX��
%	


!�
&�r.)r	r+cs�fdd�}|S)zi
    Prints error because some pipelined commands should
    be blocked when running in cluster-mode
    cstd��d���dS)Nz"ERROR: Calling pipelined function z1 is blocked when running redis in cluster mode...r�)r5rx�r	r-r/�innerds
�z%block_pipeline_command.<locals>.innerr-)r	r�r-r�r/�block_pipeline_command^sr�)EZBGREWRITEAOFr�ZBITOPZ
BRPOPLPUSHr�r�r�r�ZCLIENTr�r�r�r�ZCONFIGr�ZECHOr%r�r�r�rmr�rnzMGET NONATOMICZMOVEZMSETzMSET NONATOMICZMSETNXZPFCOUNTZPFMERGEr�ZPUBLISHror�r�ZRENAMEZRENAMENXZ	RPOPLPUSHr�r�r�r�zSCRIPT KILLr�ZSCRIPTrpZ
SDIFFSTOREz SENTINEL GET MASTER ADDR BY NAMEzSENTINEL MASTERzSENTINEL MASTERSzSENTINEL MONITORzSENTINEL REMOVEzSENTINEL SENTINELSzSENTINEL SETzSENTINEL SLAVESZSENTINELr�rqZSINTERSTOREZSLAVEOFr�r�r�ZSLOWLOGZSMOVEZSORTrrZSUNIONSTOREr�rr3c@seZdZdZddd�ZdS)r{rNcCs4||_|duri}||_||_d|_d|_d|_dS)NF)r5r6rr}r`r?)r�r5r6rr-r-r/r��szPipelineCommand.__init__)NN)r~rr�rVr�r-r-r-r/r{�sr{c@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)r�rcCs||_||_||_g|_dSru)r9r2r1�commands)r�r9r2r1r-r-r/r��szNodeCommands.__init__cCs|j�|�dSru)r�r])r�r�r-r-r/r]�szNodeCommands.appendc
Csx|j}|j}|D]
}d|_qz|�|�dd�|D���Wn8ttfyr}z|D]
}||_qRWYd}~n
d}~00dS)z=
        Code borrowed from Redis so it can be fixed
        NcSsg|]
}|j�qSr-rLr�r-r-r/rB�rCz&NodeCommands.write.<locals>.<listcomp>)r1r�r}Zsend_packed_commandZ
pack_commandsrr )r�r1r�r�r4r-r-r/r��s�zNodeCommands.writecCs�|j}|jD]�}|jdurz"|j||jdfi|j��|_Wqttfyz}z"|jD]
}||_qVWYd}~dSd}~0ty�t	�
�d|_Yq0qdS)rNrrK)r1r�r}r9r5r6rr r�sys�exc_info)r�r1r�r4r-r-r/r��s

"
zNodeCommands.readN)r~rr�rVr�r]r�r�r-r-r-r/r��s
r�)Yr�Zloggingr�rHr�r�r;�collectionsr�typingrrrrZredis.clientrrr	r
Zredis.commandsrrZredis.connectionr
rrrZ	redis.crcrrZredis.exceptionsrrrrrrrrrrrrrr r!Z
redis.lockr#Zredis.utilsr$r%r&r'r(Z	getLoggerr~r�rSr7r0r3r?rFrXrar�r�r�rsrt�	frozensetr rzr{r�r�r�rNr�rrr�ZPIPELINE_BLOCKED_COMMANDSr9�replace�lowerrBr{r�r-r-r-r/�<module>sxD
� �-
I&XG