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: //usr/lib/python3.9/site-packages/redis/asyncio/__pycache__/cluster.cpython-39.pyc
a

��b���@s(ddlZddlZddlZddlZddlZddlmZmZmZm	Z	m
Z
mZmZm
Z
mZmZddlmZddlmZmZmZmZddlmZddlmZmZmZddlmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'ddl(m)Z)dd	l*m+Z+m,Z,dd
l-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;ddl<m=Z=m>Z>m?Z?ddl@mAZAmBZBmCZCed
eDde
deedf�ZEdZFeeeDefd�dd�ZGGdd�de�ZHGdd�dee#e)�ZIGdd�d�ZJGdd�d�ZKGdd�dee#e)�ZLeD]4ZMeM�Ndd��O�ZMeMdk�r�q�ePeLeMe%eM���q�Gdd �d �ZQdS)!�N)
�Any�Deque�Dict�	Generator�List�Mapping�Optional�Type�TypeVar�Union)�ResponseCallbackT)�
Connection�
DefaultParser�Encoder�	parse_url)�CommandsParser)�EMPTY_RESPONSE�NEVER_DECODE�
AbstractRedis)
�PIPELINE_BLOCKED_COMMANDS�PRIMARY�
READ_COMMANDS�REPLICA�SLOT_ID�AbstractRedisCluster�LoadBalancer�block_pipeline_command�
get_node_name�parse_cluster_slots)�AsyncRedisClusterCommands)�REDIS_CLUSTER_HASH_SLOTS�key_slot)�AskError�BusyLoadingError�ClusterCrossSlotError�ClusterDownError�ClusterError�ConnectionError�	DataError�MasterDownError�
MovedError�RedisClusterException�
ResponseError�SlotNotCoveredError�TimeoutError�
TryAgainError)�AnyKeyT�
EncodableT�KeyT)�
dict_merge�safe_str�str_if_bytes�TargetNodesT�ClusterNode)Zclient_name�db�decode_responsesZ
encoder_class�encoding�encoding_errorsZhealth_check_interval�parser_class�password�redis_connect_funcZretryZretry_on_timeoutZsocket_connect_timeoutZsocket_keepaliveZsocket_keepalive_optionsZsocket_read_sizeZsocket_timeoutZsocket_type�username)�kwargs�returncKsdd�|��D�S)z0Remove unsupported or disabled keys from kwargs.cSsi|]\}}|tvr||�qS�)�CONNECTION_ALLOWED_KEYS)�.0�k�vrBrB�9/usr/lib/python3.9/site-packages/redis/asyncio/cluster.py�
<dictcomp>U�z"cleanup_kwargs.<locals>.<dictcomp>)�items)r@rBrBrG�cleanup_kwargsSsrKc	@s&eZdZeejeeee	e
ed��ZdS)�
ClusterParser)ZASKZTRYAGAINZMOVED�CLUSTERDOWNZ	CROSSSLOT�
MASTERDOWNN)�__name__�
__module__�__qualname__r3rZEXCEPTION_CLASSESr"r/r*r%r$r)rBrBrBrGrLXs��rLc@s`eZdZdZeeedd�dd��ZdZdTe	ee
e	edeee
e
e	eedd�
d
d�Z
dd�dd�Zdd�dd�Zdd�dd�Zddddd�dd�Zeeddfd�dd�ZdZdd�dd�Zedd�dd �Zedd�d!d"�Zedd�d#d$�Zedd�d%d&�Zdd�d'd(�Zdd�d)d*�Zddd+�d,d-�ZdUe	ee	e
e	ee	dd.�d/d0�ZdVeee	dd1�d2d3�Ze e
d4�d5d6�Z!e"d�d7d8�Z#e$ee	efd�d9d:�Z%ee&dd;�d<d=�Z'dd>�eee	eedd?�d@dA�Z(eee
dB�dCdD�Z)eedE�dFdG�Z*eeddE�dHdI�Z+e eedJ�dKdL�Z,de-e.e feedM�dNdO�Z/dWe	ee	edPdQ�dRdS�Z0dS)X�RedisClustera�

    Create a new RedisCluster client.

    Pass one of parameters:

      - `url`
      - `host` & `port`
      - `startup_nodes`

    | Use ``await`` :meth:`initialize` to find cluster nodes & create connections.
    | Use ``await`` :meth:`close` to disconnect connections & close client.

    Many commands support the target_nodes kwarg. It can be one of the
    :attr:`NODE_FLAGS`:

      - :attr:`PRIMARIES`
      - :attr:`REPLICAS`
      - :attr:`ALL_NODES`
      - :attr:`RANDOM`
      - :attr:`DEFAULT_NODE`

    Note: This client is not thread/process/fork safe.

    :param host:
        | Can be used to point to a startup node
    :param port:
        | Port used if **host** is provided
    :param startup_nodes:
        | :class:`~.ClusterNode` to used as a startup node
    :param cluster_error_retry_attempts:
        | Retry command execution attempts when encountering :class:`~.ClusterDownError`
          or :class:`~.ConnectionError`
    :param require_full_coverage:
        | When set to ``False``: 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
          :class:`~.ClusterDownError` for some key-based commands.
        | When set to ``True``: all slots must be covered to construct the cluster
          client. If not all slots are covered, :class:`~.RedisClusterException` will be
          thrown.
        | See:
          https://redis.io/docs/manual/scaling/#redis-cluster-configuration-parameters
    :param reinitialize_steps:
        | 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.
    :param read_from_replicas:
        | 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.
    :param url:
        | See :meth:`.from_url`
    :param kwargs:
        | Extra arguments that will be passed to the
          :class:`~redis.asyncio.connection.Connection` instances when created

    :raises RedisClusterException:
        if any arguments are invalid. Eg:

        - db kwarg
        - db != 0 in url
        - unix socket connection
        - none of host & url & startup_nodes were provided

    )�urlr@rAcKs|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 :class:`~redis.asyncio.connection.Connection`
        when created. In the case of conflicting arguments, querystring
        arguments always win.

        rSrB)�clsrSr@rBrBrG�from_url�s*zRedisCluster.from_url)�_initialize�_lock�cluster_error_retry_attempts�
command_flags�commands_parser�connection_kwargs�encoder�
node_flags�
nodes_manager�read_from_replicas�reinitialize_counter�reinitialize_steps�response_callbacks�result_callbacksN��F��
r7)
�host�port�
startup_nodes�require_full_coverager_rXrarSr@rAc	Ks�|sg}d|	vrtd��|rrt|�}
d|
vr4td��d|
vrP|
ddkrPtd��|	�|
�|	�d�}|	�d|�}n|rz|s�|s�td	��|j|	d
<tfi|	��|_}	|jj�	�|_
|	d<|r�|r�|�t||fi|j���t
f||d�|j��|_t|	�d
d�|	�dd�|	�dd��|_||_||_||_d|_t�|_|jj�	�|_|jj�	�|_|jj�	�|_dd�|jd<d|_t��|_ dS)Nr8z4Argument 'db' is not possible to use in cluster mode�pathzFRedisCluster does not currently support Unix Domain Socket connectionsrz9A ``db`` querystring option can only be 0 in cluster modergrha5RedisCluster 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)])r>rb)rirjr:zutf-8r;�strictr9Fc[stt|���dfi|��S)Nr)r�list�values)�cmd�resr@rBrBrG�<lambda>;s��z'RedisCluster.__init__.<locals>.<lambda>�
CLUSTER SLOTST)!r+r�update�get�
on_connectrKr[�	__class__�RESPONSE_CALLBACKS�copyrb�appendr7�NodesManagerr^rr\rXr_rar`rrZZ
NODE_FLAGSr]Z
COMMAND_FLAGSrYZRESULT_CALLBACKSrcrV�asyncio�LockrW)�selfrgrhrirjr_rXrarSr@Zurl_optionsrBrBrG�__init__�sp���

�

����


���zRedisCluster.__init__�rAc	�s�|jr�|j4IdH��|jr�d|_z*|j��IdH|j�|jj�IdHWn<ty�d|_|j��IdH|j�d�IdH�Yn0Wd�IdHq�1IdHs�0Y|S)zJGet all nodes from startup nodes & creates connections if not initialized.NFTri)rVrWr^�
initializerZ�default_node�
BaseException�close�r}rBrBrGr�As�2zRedisCluster.initializec	�s`|js\|j4IdH�2|js2d|_|j��IdHWd�IdHq\1IdHsR0YdS)z.Close all connections & client if initialized.NT)rVrWr^r�r�rBrBrGr�Ss
zRedisCluster.closec�s|��IdHS�N�r�r�rBrBrG�
__aenter__[szRedisCluster.__aenter__��exc_type�	exc_value�	tracebackrAc�s|��IdHdSr�)r��r}r�r�r�rBrBrG�	__aexit__^szRedisCluster.__aexit__cCs|����Sr��r��	__await__r�rBrBrGr�aszRedisCluster.__await__zUnclosed RedisCluster clientcCsbt|d�r^|js^tj|j�d|��t|d�z||jd�}t���|�Wnt	y\Yn0dS)NrV� ��source��client�message)
�hasattrrV�warnings�warn�_DEL_MESSAGE�ResourceWarningr{�get_event_loop�call_exception_handler�RuntimeError)r}�contextrBrBrG�__del__fszRedisCluster.__del__)�
connectionrAc�sP|�t�|��IdH|jrL|�d�IdHt|��IdH�dkrLtd��dS)NZREADONLYZOKzREADONLY command failed)Z
set_parserrLrur_Zsend_commandr5�read_response_without_lockr')r}r�rBrBrGrups
zRedisCluster.on_connectcCst|jj���S)zGet all nodes of the cluster.)rmr^�nodes_cachernr�rBrBrG�	get_nodes~szRedisCluster.get_nodescCs|j�t�S)z%Get the primary nodes of the cluster.)r^�get_nodes_by_server_typerr�rBrBrG�
get_primaries�szRedisCluster.get_primariescCs|j�t�S)z%Get the replica nodes of the cluster.)r^r�rr�rBrBrG�get_replicas�szRedisCluster.get_replicascCst�t|jj����S)z!Get a random node of the cluster.)�random�choicermr^r�rnr�rBrBrG�get_random_node�szRedisCluster.get_random_nodecCs|jjS)z#Get the default node of the client.)r^r�r�rBrBrG�get_default_node�szRedisCluster.get_default_node)�noderAcCs&|r|j|jd�std��||j_dS)z�
        Set the default node of the client.

        :raises DataError: if None is passed or node does not exist in cluster.
        ��	node_namez1The requested node does not exist in the cluster.N)�get_node�namer(r^r�)r}r�rBrBrG�set_default_node�szRedisCluster.set_default_node�rgrhr�rAcCs|j�|||�S)z&Get node by (host, port) or node_name.)r^r��r}rgrhr�rBrBrGr��szRedisCluster.get_node)�key�replicarAcCs^|�|�}|jj�|�}|s,td|�d���|rHt|jj|�dkrHdS|rRd}nd}||S)aG
        Get the cluster node corresponding to the provided key.

        :param key:
        :param replica:
            | Indicates if a replica should be returned
            |
              None will returned if no replica holds this key

        :raises SlotNotCoveredError: if the key is not covered by any slot.
        �Slot "z " is not covered by the cluster.�N�r)�keyslotr^�slots_cachertr-�len)r}r�r��slotZ
slot_cache�node_idxrBrBrG�get_node_from_key�s
zRedisCluster.get_node_from_key)r�rAcCst|j�|��S)z�
        Find the keyslot for a given key.

        See: https://redis.io/docs/manual/scaling/#redis-cluster-data-sharding
        )r!r\�encode)r}r�rBrBrGr��szRedisCluster.keyslotcCs|jS)z%Get the encoder object of the client.)r\r�rBrBrG�get_encoder�szRedisCluster.get_encodercCs|jS)zGGet the kwargs passed to :class:`~redis.asyncio.connection.Connection`.)r[r�rBrBrG�get_connection_kwargs�sz"RedisCluster.get_connection_kwargs)�command�callbackrAcCs||j|<dS)zSet a custom response callback.N)rb)r}r�r�rBrBrG�set_response_callback�sz"RedisCluster.set_response_callback)�	node_flag)r��argsr�rAc�s�|s|j�|�}||jvr�||jjkr0|jjgS||jjkrH|j�t	�S||jj
kr`|j�t�S||jjkr|t
|jj���S||jjkr�t�t
|jj����gS|j�|j|g|�R�IdH|jo�|tv�gSr�)rYrtr]rvZDEFAULT_NODEr^r�Z	PRIMARIESr�rZREPLICASrZ	ALL_NODESrmr�rnZRANDOMr�r��get_node_from_slot�_determine_slotr_r)r}r�r�r�rBrBrG�_determine_nodes�s$

��zRedisCluster._determine_nodes)r�r�rAc�s��j�|�tkrt|d�S|dvrlt|�dkrFtd|g|�R����|dd|d�}|s�t�dt�Sn@�j	j
|g|�R�IdH}|s�|dvr�t�dt�Std|����t|�dkrƈ�|d�S�fdd	�|D�}t|�dkr�t|�d
���|��S)Nr)ZEVALZEVALSHAr�zInvalid args in command: r�)ZFCALLZFCALL_ROz�No way to dispatch this command to Redis Cluster. Missing key.
You can execute the command by specifying target nodes.
Command: csh|]}��|��qSrB)r�)rDr�r�rBrG�	<setcomp>!rIz/RedisCluster._determine_slot.<locals>.<setcomp>z) - all keys must map to the same key slot)
rYrtr�intr�r+r�Z	randranger rZZget_keysr��pop)r}r�r��keys�slotsrBr�rGr��s6
����zRedisCluster._determine_slot)�target_nodesrAcCst|t�o||jvSr�)�
isinstance�strr])r}r�rBrBrG�
_is_node_flag)szRedisCluster._is_node_flagcCsPt|t�r|}n<t|t�r"|g}n*t|t�r:t|���}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�rmr7�dictrn�	TypeError�type)r}r��nodesrBrBrG�_parse_target_nodes,s


��z RedisCluster._parse_target_nodes�r�r@rAc�s��d}g}d}�j}��dd�}|rB��|�sB��|�}d}d}t|�D�]t}�jrd���IdH�z|s��j�d|i�IdH}|s�td��d	���t	|�dk�r�j
|dg��Ri���IdH}	|�jvr��j|||dj|	ifi���WS|	WSd
d�|D�}
t
j���fdd
�|D��IdH}|�jv�rf�j||tt|
|��fi���WStt|
|��WSWqJt�y�}z(t|��jjv�r�|}
n|�WYd}~qJd}~00qJ|
�dS)a|
        Execute a raw command on the appropriate cluster node or target_nodes.

        It will retry the command as specified by :attr:`cluster_error_retry_attempts` &
        then raise an exception.

        :param args:
            | Raw command args
        :param kwargs:

            - target_nodes: :attr:`NODE_FLAGS` or :class:`~.ClusterNode`
              or List[:class:`~.ClusterNode`] or Dict[Any, :class:`~.ClusterNode`]
            - Rest of the kwargs are passed to the Redis connection

        :raises RedisClusterException: if target_nodes is not provided & the command
            can't be mapped to a slot
        rFr�NTr�r��!No targets were found to execute � command oncSsg|]
}|j�qSrB�r��rDr�rBrBrG�
<listcomp>trIz0RedisCluster.execute_command.<locals>.<listcomp>c3s,|]$}t��j|g��Ri����VqdSr�)r{�
ensure_future�_execute_commandr��r�r@r}rBrG�	<genexpr>vs��z/RedisCluster.execute_command.<locals>.<genexpr>)rXr�r�r��rangerVr�r�r+r�r�rcr�r{�gatherr��zipr�r�rv�ERRORS_ALLOW_RETRY)r}r�r@r�r�Ztarget_nodes_specifiedZretry_attemptsZpassed_targets�_�retr�rn�e�	exceptionrBr�rG�execute_command@sd
��
�"
��
��
��zRedisCluster.execute_command)�target_noder�r@rAc
�sd}}d}|j}d}|dk�r|d8}zr|rP|j|d�}|�d�IdHd}n4|r�|j|�IdH}	|j�|	|jo||dtv�}d}|j|i|��IdHWSty��Yqt	t
fy�|d7}|dkr�t�d�IdHn|�
�IdH�Yqt�yb}
zV|jd7_|j�rB|j|jdk�rB|�
�IdHd|_n|
|j_d}WYd}
~
qd}
~
0t�y�||jd	k�r�t�d
�IdHYqt�y�}
z t|
j|
jd�}d}WYd}
~
qd}
~
0t�y�t�d�IdH|�
�IdH�Yq0qtd��dS)
NFrr�r�ZASKING���?Tr�g�������?�rgrhzTTL exhausted.)ZRedisClusterRequestTTLr�r�r�r^r�r_rr#r'r.r{�sleepr�r*r`ra�_moved_exceptionr/r"rrgrhr%r&)r}r�r�r@ZaskingZmovedZ
redirect_addrZttlZconnection_error_retry_counterr�r�rBrBrGr��s^
�	��
zRedisCluster._execute_command�ClusterPipeline)�transaction�
shard_hintrAcCs |rtd��|rtd��t|�S)z�
        Create & return a new :class:`~.ClusterPipeline` object.

        Cluster implementation of pipeline does not support transaction or shard_hint.

        :raises RedisClusterException: if transaction or shard_hint are truthy values
        z(shard_hint is deprecated in cluster modez)transaction is deprecated in cluster mode)r+r�)r}r�r�rBrBrG�pipeline�s

zRedisCluster.pipeline)NrdNFFrerfN)NNN)F)NN)1rOrPrQ�__doc__�classmethodr�rrU�	__slots__rr�r�boolr~r�r�r�r�rr�r�r�r
rur�r�r�r�r�r�r�r�r1r�rr�rr�rr�r�r�r�r�r�rr2r�r�rBrBrBrGrRfs�F+�
�W

��
���
� 3P�M��rRc	@s�eZdZdZdZddefeeeeee	ee
dd�dd�Zed�d	d
�Ze
e
d�dd
�ZdZdd�dd�Zdd�dd�Zed�dd�Zeee
e
d�dd�Ze
e
e
d�dd�Ze
d�dd�ZdS)r7z�
    Create a new ClusterNode.

    Each ClusterNode manages multiple :class:`~redis.asyncio.connection.Connection`
    objects for the (host, port).
    )�_command_stack�_connections�_free�connection_classr[rg�max_connectionsr�rhrb�server_typeNl)rgrhr�r�r�r[rAcKs�|dkrt�|�}||d<||d<||_||_t||�|_||_||_||_||_	|�
dtj�|_
g|_tj|jd�|_g|_dS)N�	localhostrgrhrb)�maxlen)�socket�
gethostbynamergrhrr�r�r�r�r[r�rRrwrbr��collections�dequer�r�)r}rgrhr�r�r�r[rBrBrGr~s"	
�zClusterNode.__init__rc	Cs&d|j�d|j�d|j�d|j�d�	S)Nz[host=z, port=z, name=z, server_type=�])rgrhr�r�r�rBrBrG�__repr__"s���zClusterNode.__repr__)�objrAcCst|t�o|j|jkSr�)r�r7r�)r}rrBrBrG�__eq__(szClusterNode.__eq__zUnclosed ClusterNode objectc	Csh|jD]\}|jrtj|j�d|��t|d�z||jd�}t���|�Wnt	y\Yn0qdqdS)Nr�r�r�)
r��is_connectedr�r�r�r�r{r�r�r�)r}r�r�rBrBrGr�-s
�zClusterNode.__del__c�sBtjdd�|jD�ddi�IdH}tdd�|D�d�}|r>|�dS)Ncss|]}t�|���VqdSr��r{r��
disconnect)rDr�rBrBrGr�=s�z)ClusterNode.disconnect.<locals>.<genexpr>Zreturn_exceptionsTcss|]}t|t�r|VqdSr�)r��	Exception)rDrprBrBrGr�CrI)r{r�r��next)r}r��excrBrBrGr
;s���zClusterNode.disconnectcCs�|jrHtt|j��D](}|j��}|jr0|S|j�|�q|j��St|j�|jkrz|jfi|j	��}|j�|�|St
d��dS)NzToo many connections)r�r�r��popleftrryr�r�r�r[r')r}r�r�rBrBrG�acquire_connectionGs

zClusterNode.acquire_connection)r�r�r@rAc�s|z.t|vr|jdd�IdH}n|��IdH}Wn(tyVt|vrP|tYS�Yn0||jvrx|j||fi|��S|S)NT)Zdisable_decoding)rr�r,rrb)r}r�r�r@ZresponserBrBrG�parse_responseXs�
zClusterNode.parse_responser�c	�s`|��}|�|j|�d�IdHz,|j||dfi|��IdHW|j�|�S|j�|�0dS)NFr)r�send_packed_commandZpack_commandrr�ry)r}r�r@r�rBrBrGr�ms�zClusterNode.execute_commandc�s�|��}|�|�dd�|jD��d�IdHd}|jD]\}z(|j||jdfi|j��IdH|_Wq6ty�}z||_d}WYd}~q6d}~00q6|j	�
|�|S)Ncss|]}|jVqdSr�)r��rDrorBrBrGr��rIz/ClusterNode.execute_pipeline.<locals>.<genexpr>FrT)rrZ
pack_commandsr�rr�r@�resultrr�ry)r}r�r�ror�rBrBrG�execute_pipeline{s"�


��zClusterNode.execute_pipeline)rOrPrQr�r�r
r�r�rr	rr~rr�rr�r�r
rrr�rrBrBrBrGr7�s2���c@s�eZdZdZdedeedd�dd�Zdee	ee
ee	edd�d	d
�Zdee	dfee	dfedd�dd
�Z
dd�dd�Zd e
edd�dd�Ze	edd�dd�Zdd�dd�Zd!e	dd�dd�ZdS)"rz)r�r[r�r��read_load_balancerrjr�riFr7N)rirjr@rAcKs@dd�|D�|_||_||_d|_i|_i|_t�|_d|_dS)NcSsi|]}|j|�qSrBr�r�rBrBrGrH�rIz)NodesManager.__init__.<locals>.<dictcomp>)	rirjr[r�r�r�rrr�)r}rirjr@rBrBrGr~�szNodesManager.__init__r�cCsJ|r.|r.|dkrt�|�}|j�t||d��S|r>|j�|�Std��dS)Nr�r�zEget_node requires one of the following: 1. node name 2. host and port)rrr�rtrr(r�rBrBrGr��s
�zNodesManager.get_node)�old�new�
remove_oldrAcCsx|r2t|���D] }||vrt�|�|����q|��D]8\}}||vrj|||urXq:t�||���|||<q:dSr�)rmr�r{r�r�r
rJ)r}rrrr�r�rBrBrG�	set_nodes�szNodesManager.set_nodesrcCs�|j}|j|j|jd�}|r.|jtkr\t|_n.t|j|jtfi|j��}|�|j	|j
|i�||j|jvr�|j|jd}t
|_|j|j�|�|j|j�|�||j|jd<|j|kr�||_n|g|j|j<d|_dS)Nr�r)r�r�rgrhr�rr7r[rr�r�r�Zslot_idrry�remover�)r}r�Zredirected_nodeZold_primaryrBrBrG�_update_moved_slots�s*

��
z NodesManager._update_moved_slots)r�r_rAc	Cs�|jr|��zL|rL|j|dj}|j�|t|j|��}|j||WS|j|dWSttfy�t	d|�d|j
�d���Yn0dS)Nrr�z5" not covered by the cluster. "require_full_coverage=�")r�rr�r�rZget_server_indexr��
IndexErrorr�r-rj)r}r�r_Zprimary_namer�rBrBrGr��s ���zNodesManager.get_node_from_slot)r�rAcs�fdd�|j��D�S)Ncsg|]}|j�kr|�qSrB�r�r�rrBrGr�s
�z9NodesManager.get_nodes_by_server_type.<locals>.<listcomp>)r�rn)r}r�rBrrGr�s
�z%NodesManager.get_nodes_by_server_typec�s�|j��i}i}g}d}d}|j��D�]"}z6|�d�IdH�d�sNtd��|�d�IdH}d}Wn�ttfy~Yq(Yn�t	y�}zF|�
�}	d|	vs�d|	vr�WYd}~q(ntd	|�d
|	����WYd}~nLd}~0t�y}z*|�
�}	td|j�d
|	����WYd}~n
d}~00t
|�dk�r`|d
dd
�s`t
|j�dk�r`|j|d
dd
<|D�]��tdt
���D]}
dd��|
D��|
<�qx�d}|d
}|dk�r�|j}t|d�}
|�t||
��}|�s�t||
tfi|j��}|||j<tt�d
�t�d�d�D]�}
|
|v�r�g||
<||
�|��fdd�tdt
���D�}|D]Z}|d
}|d}
|�t||
��}|�s�t||
tfi|j��}||
�|�|||j<�qZnZ||
d
}|j|jk�r|�|j�d|j�d|
���t
|�dk�rtdd�|������q�qdd}tt�D]}
|
|v�r&d}�qB�q&|r(�qNq(|�s\td��|�s�|j�r�tdt
|��dt�d���||_|j|j|dd�|j|j|jdd�|�t�d
|_d|_dS)NF�INFOZcluster_enabledz(Cluster mode is not enabled on this noderrTrMrNz7ERROR sending "cluster slots" command to redis server: z	. error: z6ERROR sending "cluster slots" command to redis server r�rr�cSsg|]}t|��qSrB)r5)rD�valrBrBrGr�OrIz+NodesManager.initialize.<locals>.<listcomp>�csg|]}�|�qSrBrB)rD�j�r�rBrGr�brIrez 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�resetrirnr�rtr+r'r.r,�__str__rr�r�rgr�r�rr7rr[ryr�joinr rjr�rr�r�r�r�)r}Ztmp_nodes_cacheZ	tmp_slotsZ
disagreementsZstartup_nodes_reachableZ
fully_coveredZstartup_nodeZ
cluster_slotsr�r��iZprimary_nodergrhr�Z
replica_nodesZreplica_nodeZtarget_replica_nodeZtmp_slotrBr#rGr�s�
��������
���

��
"
��������

����zNodesManager.initializer�)�attrrAc�s.d|_tjdd�t||���D��IdHdS)Ncss|]}t�|���VqdSr�r	r�rBrBrGr��s�z%NodesManager.close.<locals>.<genexpr>)r�r{r��getattrrn)r}r(rBrBrGr��s��zNodesManager.close)F)NNN)F)F)r�)rOrPrQr�rr�rr~rr�r�r�rrrr�r�r�r�rBrBrBrGrz�sD�����

�'��rzc@s&eZdZdZdZedd�dd�Zdd�dd	�Zdd�d
d�Zddddd�d
d�Z	e
eddfd�dd�Zdd�dd�Z
ddddd�dd�Zed�dd�Zed�dd�Zeeefedd�dd�Zd+eeeed�dd�Zd,d ed!eeeed"�d#d$�Zeedd%�d&d'�Zeeefdd(�d)d*�ZdS)-r�a�
    Create a new ClusterPipeline object.

    Usage::

        result = await (
            rc.pipeline()
            .set("A", 1)
            .get("A")
            .hset("K", "F", "V")
            .hgetall("K")
            .mset_nonatomic({"A": 2, "B": 3})
            .get("A")
            .get("B")
            .delete("A", "B", "K")
            .execute()
        )
        # result = [True, "1", 1, {"F": "V"}, True, True, "2", "3", 1, 1, 1]

    Note: For commands `DELETE`, `EXISTS`, `TOUCH`, `UNLINK`, `mset_nonatomic`, which
    are split across multiple nodes, you'll get multiple results for them in the array.

    Retryable errors:
        - :class:`~.ClusterDownError`
        - :class:`~.ConnectionError`
        - :class:`~.TimeoutError`

    Redirection errors:
        - :class:`~.TryAgainError`
        - :class:`~.MovedError`
        - :class:`~.AskError`

    :param client:
        | Existing :class:`~.RedisCluster` client
    )r��_clientN)r�rAcCs||_g|_dSr�)r*r�)r}r�rBrBrGr~�szClusterPipeline.__init__rc�s"|jjr|j��IdHg|_|Sr�)r*rVr�r�r�rBrBrGr��szClusterPipeline.initializec�s|��IdHSr�r�r�rBrBrGr��szClusterPipeline.__aenter__r�c�s
g|_dSr��r�r�rBrBrGr��szClusterPipeline.__aexit__cCs|����Sr�r�r�rBrBrGr��szClusterPipeline.__await__cCs
g|_|Sr�r+r�rBrBrG�	__enter__�szClusterPipeline.__enter__cCs
g|_dSr�r+r�rBrBrG�__exit__�szClusterPipeline.__exit__cCs
t|j�Sr�)r�r�r�rBrBrG�__bool__�szClusterPipeline.__bool__cCs
t|j�Sr�)r�r�r�rBrBrG�__len__�szClusterPipeline.__len__r�cOs(|j�tt|j�g|�Ri|���|S)ad
        Append a raw command to the pipeline.

        :param args:
            | Raw command args
        :param kwargs:

            - target_nodes: :attr:`NODE_FLAGS` or :class:`~.ClusterNode`
              or List[:class:`~.ClusterNode`] or Dict[Any, :class:`~.ClusterNode`]
            - Rest of the kwargs are passed to the Redis connection
        )r�ry�PipelineCommandr�)r}r�r@rBrBrGr��s�zClusterPipeline.execute_commandT)�raise_on_error�allow_redirectionsrAc�s�|js
gSz�t|jj�D]�}|jjr4|j��IdHz*|j|j|j||d�IdHWWg|_Sty�}zFt|�|j	j
vr�|}|j��IdHt�
d�IdHn|�WYd}~qd}~00q|�Wg|_ng|_0dS)a

        Execute the pipeline.

        It will retry the commands as specified by :attr:`cluster_error_retry_attempts`
        & then raise an exception.

        :param raise_on_error:
            | Raise the first error if there are any errors
        :param allow_redirections:
            | Whether to retry each failed command individually in case of redirection
              errors

        :raises RedisClusterException: if target_nodes is not provided & the command
            can't be mapped to a slot
        N)r1r2r�)r�r�r*rXrVr��_executer�r�rvr�r�r{r�)r}r1r2r�r�r�rBrBrG�executes.��zClusterPipeline.executerRr0)r��stackr1r2rAc�s�dd�|D�}i}|D]v}|j|j�IdH}|sBtd|j�d���t|�dkr^td|j����|d}	|	j|vr�|	||	j<g|	_|	j�|�qtjdd	�|�	�D��IdH}
t
|
��r�|�r&|D]d}t|jt
ttf�r�z |j|ji|j��IdH|_Wq�t�y"}z||_WYd}~q�d}~00q�|�r�|D]b}|j}t|t��r0d
�tt|j��}
d|jd�d|
�d
|j��}|f|jdd�|_|��q0dd�|D�S)NcSs"g|]}|jrt|jt�r|�qSrB)rr�rrrBrBrGr�Csz,ClusterPipeline._execute.<locals>.<listcomp>r�r�r�zToo many targets for command rcss|]}t�|���VqdSr�)r{r�rr�rBrBrGr�XrIz+ClusterPipeline._execute.<locals>.<genexpr>r�z
Command # � (z) of pipeline caused error: cSsg|]
}|j�qSrB)rrrBrBrGr�srI)r�r�r+r�r�r�ryr{r�rn�anyr�rr/r*r"r�r@rr&�mapr4�position)r}r�r5r1r2Ztodor�ror�r��errorsr�rr��msgrBrBrGr3<sX��

�

����zClusterPipeline._execute)r�r�rAcGs,|j�|���D]}|j|g|�R�q|Sr�)r*Z_partition_keys_by_slotrnr�)r}r�r�Z	slot_keysrBrBrG�_split_command_across_slotsusz+ClusterPipeline._split_command_across_slots)�mappingrAcCsb|jj}i}|��D](}t|�|d��}|�|g��|�q|��D]}|jdg|�R�qF|S)NrZMSET)	r*r\rJr!r��
setdefault�extendrnr�)r}r=r\Zslots_pairsZpairr��pairsrBrBrG�mset_nonatomic}szClusterPipeline.mset_nonatomic)TT)TT)rOrPrQr�r�rRr~r�r�r�rrr�r,r-r�r.r�r/rr2r1r�rr4r3r�r<rr0rArBrBrBrGr��sD$���4��:�	
�r�r�r�rAc@s.eZdZeeedd�dd�Zed�dd�ZdS)r0N)r9r�r@rAcOs||_||_||_d|_dSr�)r�r@r9r)r}r9r�r@rBrBrGr~�szPipelineCommand.__init__rcCsd|j�d|j�d|j�d�S)N�[z] r6�))r9r�r@r�rBrBrGr�szPipelineCommand.__repr__)rOrPrQr�rr~r�rrBrBrBrGr0�sr0)Rr{rr�rr��typingrrrrrrrr	r
rZredis.asyncio.clientrZredis.asyncio.connectionr
rrrZredis.asyncio.parserrZredis.clientrrrZ
redis.clusterrrrrrrrrrrZredis.commandsrZ	redis.crcr r!Zredis.exceptionsr"r#r$r%r&r'r(r)r*r+r,r-r.r/Zredis.typingr0r1r2Zredis.utilsr3r4r5r�r6rCrKrLrRr7rzr�r��replace�lower�setattrr0rBrBrBrG�<module>sP0
0@�
(]