
    +hd              	          d dl Z d dlZd dlZd dlZd dlZd dlmZmZmZm	Z	m
Z
mZmZmZmZmZmZmZ d dlmZmZ d dlmZmZmZ d dlmZ d dlmZmZmZmZ d dl m!Z! d dl"m#Z# d d	l$m%Z% d d
l&m'Z'm(Z(m)Z) d dl*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3 d dl4m5Z5m6Z6 d dl7m8Z8m9Z9 d dl:m;Z; d dl<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEmFZFmGZGmHZHmIZImJZJmKZK d dlLmMZMmNZNmOZO d dlPmQZQmRZRmSZSmTZTmUZU  edeVded   e	edf         ZW G d de      ZX G d de)e/e6      ZY G d d      ZZ G d d      Z[ G d de)e/e6      Z\e+D ]8  Z]e]j                  dd      j                         Z]e]dk(  r) e`e\e] e1e]             :  G d  d!      Zay)"    N)AnyCallableDequeDict	GeneratorListMappingOptionalTupleTypeTypeVarUnion)AsyncCommandsParserEncoder)_RedisCallbacks_RedisCallbacksRESP2_RedisCallbacksRESP3)ResponseCallbackT)
ConnectionDefaultParserSSLConnection	parse_urlLock)Retry)default_backoff)EMPTY_RESPONSENEVER_DECODEAbstractRedis)	PIPELINE_BLOCKED_COMMANDSPRIMARYREPLICASLOT_IDAbstractRedisClusterLoadBalancerblock_pipeline_commandget_node_nameparse_cluster_slots)READ_COMMANDSAsyncRedisClusterCommands)REDIS_CLUSTER_HASH_SLOTSkey_slot)CredentialProvider)AskErrorBusyLoadingErrorClusterCrossSlotErrorClusterDownErrorClusterErrorConnectionError	DataErrorMasterDownErrorMaxConnectionsError
MovedErrorRedisClusterExceptionResponseErrorSlotNotCoveredErrorTimeoutErrorTryAgainError)AnyKeyT
EncodableTKeyT)deprecated_function
dict_mergeget_lib_versionsafe_strstr_if_bytesTargetNodesTClusterNodec            
       @    e Zd Z eej
                  eeee	e
ed      Zy)ClusterParser)ASKCLUSTERDOWN	CROSSSLOT
MASTERDOWNMOVEDTRYAGAINN)__name__
__module____qualname__rA   r   EXCEPTION_CLASSESr.   r1   r0   r5   r7   r<        H/var/www/html/venv/lib/python3.12/site-packages/redis/asyncio/cluster.pyrH   rH   N   s-    "''+.)%	

rT   rH   c            N          e Zd ZdZedededd fd       ZdZdddd	d
ddddddddddd e	       ddd
ddd
ddddd
ddddd
dddf$de
e   deeef   de
ed      dededededededeeef   de
e   d e
e   d!e
e   d"e
e   d#e
e   d$e
e   d%e
e   d&ed'ed(ed)ed*e
e   d+ed,e
eeeeef   f      d-e
e   d.e
d/   d0e
eee         d1ed2e
e   d3e
e   d4ed5e
e   d6ed7e
e   d8e
e   d9e
eeegeeef   f      ddfJd:Zdud;Zdvd<Z ed=d>d?@      dvdA       ZdudBZdwdCZdeedd f   fdDZdEZ e!jD                  e#jH                  fdFedGeddfdHZ%dIe&ddfdJZ'ded   fdKZ(ded   fdLZ)ded   fdMZ*dxdNZ+dxdOZ,dydPZ-	 	 	 dzde
e   de
e   dQe
e   de
d   fdRZ.	 d{dSedTede
d   fdUZ/dSe0defdVZ1de2fdWZ3de4ee
e   f   fdXZ5de
d/   fdYZ6d|dZZ7d[ed\e8ddfd]Z9dd^d[ed_ed`e
e   ded   fdaZ:d[ed_edefdbZ;dcedefddZ<dceded   fdeZ=d_e0dedefdfZ>dgdd_ee?e0f   dedefdhZ@	 d}die
e   dje
e   ddkfdlZA	 	 	 	 	 	 d~dme?dne
e   doedpedqe
e   dre
eeB      dsedeBfdtZCy)RedisClusteraG  
    Create a new RedisCluster client.

    Pass one of parameters:

      - `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 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 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 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 cluster_error_retry_attempts:
        | Number of times to retry before raising an error when :class:`~.TimeoutError`
          or :class:`~.ConnectionError` or :class:`~.ClusterDownError` are encountered
    :param connection_error_retry_attempts:
        | Number of times to retry before reinitializing when :class:`~.TimeoutError`
          or :class:`~.ConnectionError` are encountered.
          The default backoff strategy will be set if Retry object is not passed (see
          default_backoff in backoff.py). To change it, pass a custom Retry object
          using the "retry" keyword.
    :param max_connections:
        | Maximum number of connections per node. If there are no free connections & the
          maximum number of connections are already created, a
          :class:`~.MaxConnectionsError` is raised. This error may be retried as defined
          by :attr:`connection_error_retry_attempts`
    :param address_remap:
        | An optional callable which, when provided with an internal network
          address of a node, e.g. a `(host, port)` tuple, will return the address
          where the node is reachable.  This can be used to map the addresses at
          which the nodes _think_ they are, to addresses at which a client may
          reach them, such as when they sit behind a proxy.

    | Rest of the arguments will be passed to the
      :class:`~redis.asyncio.connection.Connection` instances when created

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

        - `db` != 0 or None
        - `path` argument for unix socket connection
        - none of the `host`/`port` & `startup_nodes` were provided

    urlkwargsreturnc                     |j                  t        |             |j                  dd      t        u rd|d<    | d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

        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>

        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.

        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 are used.
        connection_classNTsslrS   )updater   popr   )clsrX   rY   s      rU   from_urlzRedisCluster.from_url   s=    8 	in%::($/=@ F5M}V}rT   )_initialize_lockcluster_error_retry_attemptscommand_flagscommands_parserconnection_error_retry_attemptsconnection_kwargsencoder
node_flagsnodes_managerread_from_replicasreinitialize_counterreinitialize_stepsresponse_callbacksresult_callbacksNi  TF              r   zredis-pyzutf-8strictrequired   hostportstartup_nodesrF   require_full_coveragerl   rn   rd   rg   max_connectionsdbpathcredential_providerusernamepasswordclient_namelib_namelib_versionencodingencoding_errorsdecode_responseshealth_check_intervalsocket_connect_timeoutsocket_keepalivesocket_keepalive_optionssocket_timeoutretryr   retry_on_errorr]   ssl_ca_certsssl_ca_datassl_cert_reqsssl_certfilessl_check_hostnamessl_keyfileprotocoladdress_remapc%           
         |
rt        d      |rt        d      |r|s|st        d      i d|	dt        dt        d|d|d	|d
|d|d|d|d|d|d|d|d|d|d|||#d}%|r|%j                  t        |||| |!|"d       |r| j
                  |%d<   || _        |s|s|dkD  rc|xs t        t               |      | _        |st        t        g}| j                  j                  |       |%j                  d| j                  i       t        j                         |%d<   |%j                  d      dv r|%d   j                  t               n|%d   j                  t                |%| _        |rFg }&|D ]<  }'|&j%                  t'        |'j(                  |'j*                  fi | j"                         > |&}ng }|r(|r&|j%                  t'        ||fi | j"                         t-        |||%|$      | _        t1        |||      | _        || _        || _        || _        || _        d| _        t?               | _         | jB                  jD                  j                         | _#        | jB                  jH                  j                         | _%        |%d   | _&        | jB                  jN                  j                         | _(        d | jP                  d<   d | _)        d | _*        y )!Nz/Argument 'db' must be 0 or None in cluster modez3Unix domain socket is not supported in cluster modea1  RedisCluster requires at least one node to discover the cluster.
Please provide one of the following or use RedisCluster.from_url:
   - host and port: RedisCluster(host="localhost", port=6379)
   - startup_nodes: RedisCluster(startup_nodes=[ClusterNode("localhost", 6379), ClusterNode("localhost", 6380)])r{   r\   parser_classr~   r   r   r   r   r   r   r   r   r   r   r   r   r   )r   r   )r\   r   r   r   r   r   r   redis_connect_funcr   r   ro   r   )3rr   r   c                 N    t        t        |j                               d   fi |S )Nr   )r(   listvalues)cmdresrY   s      rU   <lambda>z'RedisCluster.__init__.<locals>.<lambda>  s'    ':q!(
%+(
 rT   CLUSTER SLOTST)+r8   r   rH   r^   r   
on_connectr   r   r   r3   r;   update_supported_errorsr   copygetr   r   rh   appendrF   rw   rx   NodesManagerrk   r   ri   rl   rn   rd   rg   rm   r   rf   	__class__
NODE_FLAGSrj   COMMAND_FLAGSre   ro   RESULT_CALLBACKSrp   rb   rc   )(selfrw   rx   ry   rz   rl   rn   rd   rg   r{   r|   r}   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r]   r   r   r   r   r   r   r   r   rY   passed_nodesnodes(                                           rU   __init__zRedisCluster.__init__   s   X 'A  'E  D-'S "
"

"
 M"

 "#6"
 "
 "
 ;"
 "
 ;"
 "
 "
  0"
  $%:!"
" %&<#"
$  0%"
& '(@'"
( n)"
*  -"
2 MM(5$0#.%2$0*<#.
 +/??F'(
N&E&I %!#B#DJ ""1<!@JJ..~>MM7DJJ/0'6';';'=#$::j!X-'(//0DE'(//0DE!'L% ##		499O8N8NO )MMD  T4!R4;Q;Q!RS)!'	
 x:JK"4"4,H)/N,$%!24..3388:!^^99>>@"()="> $ ? ? D D F
 		
  -1
rT   c                 ~  K   | j                   r| j                  st        j                         | _        | j                  4 d{    | j                   ra	 | j                  j                          d{    | j                  j                  | j                  j                         d{    d| _         ddd      d{    | S | S 7 7 X7 ## t        $ rI | j                  j                          d{  7   | j                  j                  d       d{  7    w xY w7 c# 1 d{  7  sw Y   | S xY ww)zJGet all nodes from startup nodes & creates connections if not initialized.NFry   )
rb   rc   asyncior   rk   
initializerf   default_nodeBaseExceptionacloser   s    rU   r   zRedisCluster.initialize  s    ::$\\^
zz  ##	"00;;==="22== ..;;   ,1(  t > ) "0077999"0077HHH    s   AD=C
D=D'C3C46C*C+C6D=D%	D=CC&D"6C97#D"DD""D'%D='D:-D0.D:5D=c                   K   | j                   s| j                  st        j                         | _        | j                  4 d{    | j                   sLd| _         | j                  j                          d{    | j                  j                  d       d{    ddd      d{    yy7 n7 ;7 7 # 1 d{  7  sw Y   yxY ww)z.Close all connections & client if initialized.NTry   )rb   rc   r   r   rk   r   r   s    rU   r   zRedisCluster.aclose  s     ::$\\^
zz E E'''+D$,,33555,,33ODDD	E E E  E 6D	E E E Esl   ACB3C1B;9B5:"B;B7B;!C,B9-C5B;7B;9C;CCC	Cz5.0.0zUse aclose() insteadclose)versionreasonnamec                 @   K   | j                          d{    y7 w)z.alias for aclose() for backwards compatibilityNr   r   s    rU   r   zRedisCluster.close  s      kkm   c                 >   K   | j                          d {   S 7 wNr   r   s    rU   
__aenter__zRedisCluster.__aenter__       __&&&&   c                 @   K   | j                          d {    y 7 wr   r   r   exc_type	exc_value	tracebacks       rU   	__aexit__zRedisCluster.__aexit__  s     kkmr   c                 >    | j                         j                         S r   r   	__await__r   s    rU   r   zRedisCluster.__await__       **,,rT   zUnclosed RedisCluster client_warn_grlc                     t        | d      rR| j                  sE || j                   d| t        |        	 | | j                  d} |       j	                  |       y y y # t
        $ r Y y w xY w)Nrb    sourceclientmessage)hasattrrb   _DEL_MESSAGEResourceWarningcall_exception_handlerRuntimeError)r   r   r   contexts       rU   __del__zRedisCluster.__del__  sv    
 4'0@0@T&&'q1?4P%)d6G6GH--g6	 1A'
   s   %A   	A,+A,
connectionc                    K   |j                          d {    |j                  d       d {    t        |j                          d {         dk7  rt	        d      y 7 M7 67 w)NREADONLYOKzREADONLY command failed)r   send_commandrD   read_responser3   r   r   s     rU   r   zRedisCluster.on_connect  sh     ##%%% %%j111j66889TA!";<< B 	& 	28s1   A*A$A*A&A*A(A*&A*(A*c                 \    t        | j                  j                  j                               S )zGet all nodes of the cluster.)r   rk   nodes_cacher   r   s    rU   	get_nodeszRedisCluster.get_nodes  s"    D&&2299;<<rT   c                 @    | j                   j                  t              S )z%Get the primary nodes of the cluster.)rk   get_nodes_by_server_typer!   r   s    rU   get_primarieszRedisCluster.get_primaries      !!::7CCrT   c                 @    | j                   j                  t              S )z%Get the replica nodes of the cluster.)rk   r   r"   r   s    rU   get_replicaszRedisCluster.get_replicas  r   rT   c                     t        j                  t        | j                  j                  j                                     S )z!Get a random node of the cluster.)randomchoicer   rk   r   r   r   s    rU   get_random_nodezRedisCluster.get_random_node  s+    }}T$"4"4"@"@"G"G"IJKKrT   c                 .    | j                   j                  S )z#Get the default node of the client.)rk   r   r   s    rU   get_default_nodezRedisCluster.get_default_node  s    !!...rT   c                 x    |r| j                  |j                        st        d      || j                  _        y)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_noder   r4   rk   r   )r   r   s     rU   set_default_nodezRedisCluster.set_default_node  s2     4==499==OPP*.'rT   r   c                 <    | j                   j                  |||      S )z&Get node by (host, port) or node_name.)rk   r   r   rw   rx   r   s       rU   r   zRedisCluster.get_node  s     !!**4yAArT   keyreplicac                     | j                  |      }| j                  j                  j                  |      }|st	        d| d      |r-t        | j                  j                  |         dk  ryd}||   S d}||   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.rv   N   r   )keyslotrk   slots_cacher   r:   len)r   r   r   slot
slot_cachenode_idxs         rU   get_node_from_keyzRedisCluster.get_node_from_key  s     ||C ''3377=
%tf4T&UVV4%%11$781<H (## H(##rT   c                 J    t        | j                  j                  |            S )z
        Find the keyslot for a given key.

        See: https://redis.io/docs/manual/scaling/#redis-cluster-data-sharding
        )r,   ri   encode)r   r   s     rU   r  zRedisCluster.keyslot  s     ++C011rT   c                     | j                   S )z%Get the encoder object of the client.)ri   r   s    rU   get_encoderzRedisCluster.get_encoder  s    ||rT   c                     | j                   S )zGGet the kwargs passed to :class:`~redis.asyncio.connection.Connection`.)rh   r   s    rU   get_connection_kwargsz"RedisCluster.get_connection_kwargs  s    %%%rT   c                     | j                   S r   )r   r   s    rU   	get_retryzRedisCluster.get_retry!  s    zzrT   c                     || _         | j                         D ]7  }|j                  j                  d|i       |j                  D ]	  }||_          9 y )Nr   )r   r   rh   r^   _connections)r   r   r   conns       rU   	set_retryzRedisCluster.set_retry$  sT    
NN$ 	#D""))7E*:;)) #"
#	#rT   commandcallbackc                 "    || j                   |<   y)zSet a custom response callback.N)ro   )r   r  r  s      rU   set_response_callbackz"RedisCluster.set_response_callback+  s    +3(rT   )	node_flagargsr  c                z  K   |s| j                   j                  |      }|| j                  v r@|| j                  j                  k(  r| j
                  j                  gS || j                  j                  k(  r| j
                  j                  t              S || j                  j                  k(  r| j
                  j                  t              S || j                  j                  k(  r-t        | j
                  j                  j                               S || j                  j                   k(  rAt#        j$                  t        | j
                  j                  j                                     gS | j
                  j'                   | j(                  |g|  d {   | j*                  xr |t,        v       gS 7 wr   )re   r   rj   r   DEFAULT_NODErk   r   	PRIMARIESr   r!   REPLICASr"   	ALL_NODESr   r   r   RANDOMr   r   get_node_from_slot_determine_slotrl   r)   )r   r  r  r  s       rU   _determine_nodeszRedisCluster._determine_nodes/  sd    
 **..w7I'DNN777**7788DNN444))BB7KKDNN333))BB7KKDNN444D..::AACDDDNN111d4+=+=+I+I+P+P+R&STUU 11*d**7:T::''DG},D
 	
:s   FF;F9F;c                   K   | j                   j                  |      t        k(  rt        |d         S |j	                         dv rPt        |      dk  rt        d|g|       |ddt        |d         z    }|s{t        j                  dt              S  | j                  j                  |g|  d {   }|s:|j	                         dv rt        j                  dt              S t        d|       t        |      dk(  r| j                  |d         S |D ch c]  }| j                  |       }}t        |      dk7  rt        | d      |j                         S 7 c c}w w)	Nr   )EVALEVALSHArv   zInvalid args in command: r   )FCALLFCALL_ROzNo 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)re   r   r#   intupperr  r8   r   	randranger+   rf   get_keysr  r_   )r   r  r  keysr   slotss         rU   r!  zRedisCluster._determine_slotQ  sy    !!'*g5tAw< ==?114y1}+/$/?@  ADG,-D ''+CDD6--66wFFFD ==?&;;!++A/GHH+//3f6  t9><<Q(( /33sc"33u:?')DE  yy{1 G$ 4s%   B3E)5E"6A&E)E$4/E)$E)target_nodesc                 B    t        |t              xr || j                  v S r   )
isinstancestrrj   )r   r.  s     rU   _is_node_flagzRedisCluster._is_node_flag  s    ,,P1PPrT   c                     t        |t              r|}|S t        |t              r|g}|S t        |t              rt        |j	                               }|S t        dt        |             )Nztarget_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 )r0  r   rF   dictr   	TypeErrortype)r   r.  nodess      rU   _parse_target_nodesz RedisCluster._parse_target_nodes  s    lD) E   k2!NE  d+ ,,./E  & '+<&8%9; rT   c           
      |   K   d   }g }d} j                   }j                  dd      }|r& j                  |      s j                  |      }d}d}d|z   }t	        |      D ]  }	 j
                  rL j                          d{    t        |      dk(  r&|d    j                         k(  r j                          	 |s+  j                  d|i d{   }|st        d d	      t        |      dk(  r[  j                  |d   gi  d{   }
| j                  v r(  j                  |   ||d   j                  |
ifi c S |
c S |D cg c]  }|j                   }}t        j                    fd
|D          d{   }| j                  v r,  j                  |   |t#        t%        ||            fi c S t#        t%        ||            c S  y7 a7 7 c c}w 7 d# t&        $ r8}|dkD  r,t)        |       j*                  j,                  v r|dz  }Y d}~|d}~ww xY ww)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
        r   Fr.  NTr   r  !No targets were found to execute  command onc              3   p   K   | ]-  }t        j                   j                  |gi        / y wr   )r   create_task_execute_command).0r   r  rY   r   s     rU   	<genexpr>z/RedisCluster.execute_command.<locals>.<genexpr>  s@       !% $// 5 5 5d LT LV Ls   36)rd   r_   r2  r8  rangerb   r   r  r   replace_default_noder"  r8   r>  rp   r   r   gatherr4  zip	Exceptionr6  r   ERRORS_ALLOW_RETRY)r   r  rY   r  r.  target_nodes_specifiedretry_attemptspassed_targetsexecute_attempts_retr   r,  r   es   ```            rU   execute_commandzRedisCluster.execute_command  s    $ q'!&::ND9$"4"4^"D33NCL%)"N ~-'( 3	Aoo'''%*$Q4+@+@+BB --/*-)>)>)>*)7* $L (3?v[Q  |$) 5 5 5l1o W WPV WWC$"7"77=t44W=#l1o&:&:C%@ DJ   J2>?$DII?D?#*>> )5	$ F $"7"77=t44W=#T#dF*;%< @F    D& 122U3	'$ X @  !A%$q'T^^5V5V*V #a'N Gs   BH<G)	8H<G8G,?G8G/7G8H<G8H<G8G1/"G8G6;G8H<G8$H<,G8/G81G88	H9+H4,H<2H44H99H<target_nodec                   K   dx}}d }| j                   }|dkD  r|dz  }	 |r.| j                  |      }|j                  d       d {    d}nN|rL | j                  |  d {   }| j                  j                  || j                  xr |d   t        v       }d} |j                  |i | d {   S t9        d      7 z7 `7 # t        t        f$ r  t        t        f$ rK | j                  j                  j                  |j                  d        | j                          d {  7    t         $ r9 | j                          d {  7   t#        j$                  d       d {  7    t&        $ r{}	| xj(                  dz  c_        | j*                  r=| j(                  | j*                  z  dk(  r!| j                          d {  7   d| _        n|	| j                  _        d}Y d }	~	nvd }	~	wt.        $ r-}	t1        |	j2                  |	j4                        }d}Y d }	~	nBd }	~	wt6        $ r3 || j                   d	z  k  rt#        j$                  d
       d {  7   Y nw xY w|dkD  rRw)NFr   r   r   ASKING      ?Trw   rx   rv   g?zTTL exhausted.)RedisClusterRequestTTLr   rN  r!  rk   r   rl   r)   r/   r6   r3   r;   ry   r_   r   r   r1   r   sleepr7   rm   rn   _moved_exceptionr.   r'   rw   rx   r<   r2   )
r   rO  r  rY   askingmovedredirect_addrttlr  rM  s
             rU   r>  zRedisCluster._execute_command  s>     ))Ag1HC;."&----"HK%55h???"F "6!5!5t!<<D"&"4"4"G"Gd55R$q']:R#K "E8[88$I&III^ +,,u @
 = J$&9: #\2 	
 ""0044[5E5EtL kkm###  kkm##mmD)))  ))Q.)++11D4K4KKqP++-''01D-:;D&&7  -166 G  .44q88!-----.w Ags   I.(C	 C	C	 $C%AC	 3C4C	 7I.C	 C	 C	 	A!I"*D-+!I"EI"*E-+I"9AG/	G
 G/*I./I";#H#I.#6I"II"I.!I""I.transaction
shard_hintClusterPipelinec                 L    |rt        d      |rt        d      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)r8   r]  )r   r[  r\  s      rU   pipelinezRedisCluster.pipeline7  s-     '(RSS'(STTt$$rT   r   timeoutrU  blockingblocking_timeout
lock_classthread_localc           	      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.)r`  rU  ra  rb  rd  r   )r   r   r`  rU  ra  rb  rc  rd  s           rU   lockzRedisCluster.lockI  s2    | J-%
 	
rT   )rZ   rW   rZ   Nr   Nr   Nr   NrZ   N)rZ   rF   )r   rF   rZ   NNNNF)r   r   rZ   N)NN)Ng?TNNT)DrO   rP   rQ   __doc__classmethodr1  r   ra   	__slots__rB   r
   r   r(  r   boolr-   floatr	   bytesr   rE  r   r   r   r   r   r@   r   r   r   r   r   r   warningswarnr   get_running_loopr   r   r   r   r   r   r   r   r   r   r  r>   r  r   r  r   r  r  r  r   r  r"  r!  r2  r8  rN  r?   r>  r_  r   rf  rS   rT   rU   rW   rW   \   s:   Qf 3 # .  @I( # $7;&*#("#,-/0$"<@"&"&%)",%4%6'!&'(26!&NR*.#':>&*%)'&*#(%)"#IMUa2sma2 CHoa2
  ] 34a2  $a2 !a2  a2 '*a2 *-a2 a2 #s(Oa2 sma2 &&89a2  3-!a2" 3-#a2$ c]%a2& 3-'a2( c])a2, -a2. /a20 1a24  %5a26 !)7a28 9a2: #+73c5j8I3I+J"K;a2< !=a2>  ?a2@ !d9o!67Aa2D Ea2F smGa2H c]Ia2J Ka2L smMa2N !Oa2P c]Qa2R 3-Sa2T  #sU38_)D EFUa2V 
Wa2F&	E 1GgV W'-9S$%>? - 2L ]],,  
	
=: 
=$ 
==4. =DtM2 DDd=1 DL/	/ #"#'	BsmB smB C=	B
 
-	 B ).$$!%$	-	 $82: 2# 2W &tC#,>'? &8G, #4S 4<M 4RV 4
 DH 
 
#& 
3;C= 
	m	 
D1S 1 1 1fQ# Q$ Q ]8K (R: R R RhF-(F-16tZ7G1HF-TWF-	F-R NR%#C=%=Ec]%	%* $(,0+/!H
H
 %H
 	H

 H
 #5/H
 T$Z(H
 H
 
H
rT   rW   c                      e Zd ZdZdZ	 d deddedeeef   de	e   d	ed
e
e   deddfdZdefdZdedefdZdZej$                  ej(                  fdededdfdZd!dZdefdZdedededefdZdededefdZded   defdZy)"rF   z
    Create a new ClusterNode.

    Each ClusterNode manages multiple :class:`~redis.asyncio.connection.Connection`
    objects for the (host, port).
    )
r  _freer\   rh   rw   r{   r   rx   ro   server_typeNrs   )r{   r\   rw   rx   rv  r{   r\   rh   rZ   c                H   |dk(  rt        j                  |      }||d<   ||d<   || _        || _        t	        ||      | _        || _        || _        || _        || _	        |j                  di       | _        g | _        t        j                  | j                        | _        y )N	localhostrw   rx   ro   )maxlen)socketgethostbynamerw   rx   r'   r   rv  r{   r\   rh   r_   ro   r  collectionsdequeru  )r   rw   rx   rv  r{   r\   rh   s          rU   r   zClusterNode.__init__  s     ;''-D$(&!$(&!		!$-	&. 0!2"3"7"78Lb"Q.0(3(9(9AUAU(V
rT   c           	      p    d| j                    d| j                   d| j                   d| j                   d	S )Nz[host=z, port=z, name=z, server_type=])rw   rx   r   rv  r   s    rU   __repr__zClusterNode.__repr__  s?    TYYKwtyyk 2II;nT-=-=,>aA	
rT   objc                 X    t        |t              xr |j                  | j                  k(  S r   )r0  rF   r   )r   r  s     rU   __eq__zClusterNode.__eq__  s!    #{+EDII0EErT   zUnclosed ClusterNode objectr   r   c                     | j                   D ]T  }|j                  s || j                   d| t        |        	 | | j                  d} |       j	                  |        y  y # t
        $ r Y  y w xY w)Nr   r   r   )r  is_connectedr   r   r   r   )r   r   r   r   r   s        rU   r   zClusterNode.__del__  s    
 ++ 		J&&**+1TH5tT)-$:K:KLGF11': 		 $ s   %A%%	A21A2c                    K   t        j                  d | j                  D        ddi d {   }t        d |D        d       }|r|y 7 w)Nc              3   b   K   | ]'  }t        j                  |j                                ) y wr   r   r=  
disconnect)r?  r   s     rU   r@  z)ClusterNode.disconnect.<locals>.<genexpr>  s,       ##J$9$9$;<   -/return_exceptionsTc              3   B   K   | ]  }t        |t              s|  y wr   )r0  rE  )r?  r   s     rU   r@  z)ClusterNode.disconnect.<locals>.<genexpr>  s     EC*S)*DCEs   )r   rC  r  next)r   rL  excs      rU   r  zClusterNode.disconnect  s\     NN"&"3"3

 #
 
 E3EtLI 
s   *AA	Ac                     	 | j                   j                         S # t        $ rh t        | j                        | j
                  k  r; | j                  di | j                  }| j                  j                  |       |cY S t               w xY w)NrS   )
ru  popleft
IndexErrorr  r  r{   r\   rh   r   r6   r   s     rU   acquire_connectionzClusterNode.acquire_connection  s    	(::%%'' 	(4$$%(<(<<2T22LT5K5KL
!!((4!!%''	(s    A$BBr   r  rY   c                 |  K   	 t         |v r0|j                  d       d {   }|j                  t                n|j                          d {   }t        |v r|j                  t               || j
                  v r | j
                  |   |fi |S |S 7 u7 I# t        $ r t        |v r|t           cY S  w xY ww)NT)disable_decoding)r   r   r_   r9   r   ro   )r   r   r  rY   responses        rU   parse_responsezClusterNode.parse_response  s     		v%!+!9!94!9!PP

<(!+!9!9!;; V#JJ~& d---34**73HGGG! Q < 	'n--	sK   B<B B-B BB AB<B B B95B<7B99B<r  c                 6  K   | j                         }|j                   |j                  | d       d {    	  | j                  ||d   fi | d {   | j                  j                  |       S 7 ?7 !# | j                  j                  |       w xY ww)NFr   )r  send_packed_commandpack_commandr  ru  r   )r   r  rY   r   s       rU   rN  zClusterNode.execute_command  s     ,,.
 ,,-DZ-D-Dd-KUSSS	*,,,ZaKFKK JJj) 	T L JJj)s8   3BA5BA9 A7A9 B7A9 9BBcommandsPipelineCommandc                   K   | j                         }|j                  |j                  d |D              d       d {    d}|D ];  }	  | j                  ||j                  d   fi |j
                   d {   |_        = | j                  j                  |       |S 7 c7 *# t        $ r}||_        d}Y d }~vd }~ww xY ww)Nc              3   4   K   | ]  }|j                     y wr   )r  )r?  r   s     rU   r@  z/ClusterNode.execute_pipeline.<locals>.<genexpr>"  s     $B#SXX$Bs   Fr   T)
r  r  pack_commandsr  r  rY   resultrE  ru  r   )r   r  r   rL  r   rM  s         rU   execute_pipelinezClusterNode.execute_pipeline  s     ,,.
 ,,$$$B$BBE
 	
 	

  	C#64#6#6$/2zz$ 
	 	

*%
%	
  
sK   <CB"C.B&9B$:	B& C$B&&	C/	B=8C=CCr   rg  )rO   rP   rQ   rk  rm  r   r1  r   r(  r
   r   r   r   r  rn  r  r   rq  rr  r   rs  r   r  r  r  rN  r   r  rS   rT   rU   rF   rF     sH   I" &*	W  %-7WW CHoW c]	W W z*W !W 
W8
# 
F# F$ F 1L ]],,  
	 
	(J 	($/2>A	.*3 *# *# *t4E/F 4 rT   c                   4   e Zd ZdZ	 dded   dedeeef   de	e
eegeeef   f      ddf
d	Z	 	 	 dd
e	e   de	e   de	e   de	d   fdZ	 ddeedf   deedf   deddfdZddZ	 ddededdfdZdeded   fdZddZd deddfdZd
ededeeef   fdZy)!r   )	rV  rh   r   r   read_load_balancerrz   r  ry   r   Nry   rF   rz   rh   r   rZ   c                     |D ci c]  }|j                   | c}| _        || _        || _        || _        d | _        i | _        i | _        t               | _	        d | _
        y c c}w r   )r   ry   rz   rh   r   r   r   r  r%   r  rV  )r   ry   rz   rh   r   r   s         rU   r   zNodesManager.__init__C  sh     ;HH$diioH%:"!2*+/57;="..,0 Is   A"rw   rx   r   c                     |rB|r@|dk(  rt        j                  |      }| j                  j                  t	        ||            S |r| j                  j                  |      S t        d      )Nrx  rS  zEget_node requires one of the following: 1. node name 2. host and port)rz  r{  r   r   r'   r4   r   s       rU   r   zNodesManager.get_nodeU  sk     D{"++D1##''4d(KLL##''	22# rT   oldnew
remove_oldc                 P   |rUt        |j                               D ]9  }||vst        j                  |j	                  |      j                               }; |j                         D ]<  \  }}||v r.||   |u rt        j                  ||   j                               }|||<   > y r   )r   r,  r   r=  r_   r  items)r   r  r  r  r   taskr   s          rU   	set_nodeszNodesManager.set_nodesi  s     SXXZ( Ks?"..swwt}/G/G/IJDK ))+ 	JD$s{t9$**3t9+?+?+ABCI	rT   c                 6   | j                   }| j                  |j                  |j                        }|r|j                  t
        k7  rdt
        |_        nXt        |j                  |j                  t
        fi | j                  }| j                  | j                  |j                  |i       || j                  |j                     v r| j                  |j                     d   }t        |_        | j                  |j                     j                  |       | j                  |j                     j                  |       || j                  |j                     d<   | j                   |k(  r)|| _        d | _         y |g| j                  |j                  <   d | _         y )NrS  r   )rV  r   rw   rx   rv  r!   rF   rh   r  r   r   r  slot_idr"   r   remover   )r   rM  redirected_nodeold_primarys       rU   _update_moved_slotsz NodesManager._update_moved_slots{  s\   !!--QVV!&&-A**g5.5+ *+/+A+AO NN4++o.B.BO-TUd..qyy99 **1995a8K '.K#QYY'..{; QYY'..?-<DQYY'*  K/$3! !% ,;*;DQYY' $rT   r  rl   c                    | j                   r| j                          	 |r`| j                  |   d   j                  }| j                  j                  |t        | j                  |               }| j                  |   |   S | j                  |   d   S # t        t        f$ r t        d| d| j                   d      w xY w)Nr   r   z5" not covered by the cluster. "require_full_coverage=")rV  r  r  r   r  get_server_indexr  r  r5  r:   rz   )r   r  rl   primary_namer  s        rU   r   zNodesManager.get_node_from_slot  s       $$&	!#//5a8==22CC #d&6&6t&<"= ''-h77##D)!,,I& 	% **.*D*D)EQH 	s   A!B  B ,B>rv  c                 z    | j                   j                         D cg c]  }|j                  |k(  r| c}S c c}w r   )r   r   rv  )r   rv  r   s      rU   r   z%NodesManager.get_nodes_by_server_type  sA     ((//1
;. 
 	
 
s   8c           
      4  K   | j                   j                          i }i }g }d}d}d }| j                  j                         D ]  }	 |j	                  d       d {   j                  d      st        d      |j	                  d       d {   }d}t        |      dk(  r8|d   d	   d   s-t        | j                        dk(  r|j                  |d   d	   d<   |D ]/  }
t        d	t        |
            D ]!  }|
|   D cg c]  }t        |       c}|
|<   # |
d	   }|d   }|d
k(  r|j                  }t        |d         }| j                  ||      \  }}|j                  t        ||            }|st        ||t         fi | j"                  }|||j$                  <   t        t        |
d         t        |
d         dz         D ]B  }||vrg ||<   ||   j'                  |       t        dt        |
            D cg c]  }|
|   	 }}|D ]}  }|d   }|d   }| j                  ||      \  }}|j                  t        ||            }|st        ||t(        fi | j"                  }||   j'                  |       |||j$                  <    ||   d   }|j$                  |j$                  k7  s|j'                  |j$                   d|j$                   d|        t        |      dkD  s(t        ddj+                  |              2 d}t        t,              D ]
  }||vsd} n |s n |st        dt/        |             ||s+| j0                  rt        dt        |       dt,         d      || _        | j5                  | j6                  |d       | j5                  | j                  | j6                  d       | j9                  t               d   | _        d | _        y 7 7 c# t        $ r}	|	}Y d }	~	d }	~	ww xY wc c}w c c}w w)NFINFOcluster_enabledz(Cluster mode is not enabled on this noder   Tr   r   rv    rr   z vs z
 on slot: rq   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  resetry   r   rN  r   r8   rE  r  rw   rA  rD   r(  remap_host_portr'   rF   r!   rh   r   r   r"   joinr+   r1  rz   r  r  r   r   r   rV  )r   tmp_nodes_cache	tmp_slotsdisagreementsstartup_nodes_reachablefully_covered	exceptionstartup_nodecluster_slotsrM  r  ivalprimary_noderw   rx   rO  jreplica_nodesreplica_nodetarget_replica_nodetmp_slots                         rU   r   zNodesManager.initialize  s    %%'4646	"'	 ..557 ^	L*::6BBGG% 0B  '3&B&B?&S S*.' M"a'%a(+A.**+q0)5):):a #A&% 6"q#d), EA<@GDS|C0DDGE#Aw#A2:',,D<?+!11$=
d-11-d2KL""-dG#/3/E/E#K 5@ 0 01s47|Sa\A-=> $"A	)')	!!!++K8:?3t9:M(NQa(N(N,9 4L#/?D#/?D)-)=)=dD)IJD$2A2E2E -dD 93/ $76A$($7";?;Q;Q7" 3 &aL//0CD !4 , 3 8 84( $-Q<?#==K,<,<<)00#+==/k6F6F5GzRSQT U  #=1A5&;'448IIm4L3M%O'" !"C$"%6"r !M34 I%$)M }^	@ ''''*9~&68  !;!; (Ky>"$'?&@ A  %t''TJt))4+;+;M !99'B1E $m C !T  		, E( )Os   APO5O/2O5O2O5A+PP
C-P P
B&P3;P09P*P3B<P/O52O55	P>P PPPattrc                    K   d | _         t        j                  d t        | |      j	                         D          d {    y 7 w)Nc              3   b   K   | ]'  }t        j                  |j                                ) y wr   r  r?  r   s     rU   r@  z&NodesManager.aclose.<locals>.<genexpr>C  s*       ##DOO$56r  )r   r   rC  getattrr   )r   r  s     rU   r   zNodesManager.aclose@  sA      nn#D$/668
 	
 	
s   <AAAc                 H    | j                   r| j                  ||f      S ||fS )z
        Remap the host and port returned from the cluster to a different
        internal value.  Useful if the client is not connecting directly
        to the cluster.
        r   )r   rw   rx   s      rU   r  zNodesManager.remap_host_portI  s,     %%tTl33TzrT   r   ri  rj  rg  )r   )rO   rP   rQ   rm  r   rn  r   r1  r   r
   r   r(  r   r   r   r  r  r   r   r   r   r  rS   rT   rU   r   r   6  st   
I" JN1M*1  $1  S>	1
  #sU38_)D EF1 
1( #"#'	sm sm C=	
 
-	 0 !	#}$% #}$% 	
 
$$%N 5:-1	*
C 
D<O 
A%F
 
 
C s uS#X rT   r   c                      e Zd ZdZdZdeddfdZddZddZdd	Z	de
edd f   fd
ZddZddZdefdZdefdZdeeef   dedd fdZ	 d dededee   fdZ	 	 d ddded   dededee   f
dZdededd fdZdeeef   dd fdZy)!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
    )_command_stack_clientr   rZ   Nc                      || _         g | _        y r   )r  r  )r   r   s     rU   r   zClusterPipeline.__init__{  s    79rT   c                    K   | j                   j                  r"| j                   j                          d {    g | _        | S 7 wr   )r  rb   r   r  r   s    rU   r   zClusterPipeline.initialize  s;     <<##,,))+++  ,s   4AAAc                 >   K   | j                          d {   S 7 wr   r   r   s    rU   r   zClusterPipeline.__aenter__  r   r   c                    K   g | _         y wr   r  r   s       rU   r   zClusterPipeline.__aexit__  s      s   	c                 >    | j                         j                         S r   r   r   s    rU   r   zClusterPipeline.__await__  r   rT   c                     g | _         | S r   r  r   s    rU   	__enter__zClusterPipeline.__enter__  s     rT   c                     g | _         y r   r  r   s       rU   __exit__zClusterPipeline.__exit__  s
     rT   c                 ,    t        | j                        S r   )rn  r  r   s    rU   __bool__zClusterPipeline.__bool__  s    D''((rT   c                 ,    t        | j                        S r   )r  r  r   s    rU   __len__zClusterPipeline.__len__  s    4&&''rT   r  rY   c                 |    | j                   j                  t        t        | j                         g|i |       | 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  r   r  r  )r   r  rY   s      rU   rN  zClusterPipeline.execute_command  s<     	""C 3 34FtFvF	
 rT   raise_on_errorallow_redirectionsc                 p  K   | j                   sg S 	 t        | j                  j                        D ]t  }| j                  j                  r"| j                  j                          d{    	 | j                  | j                  | j                   ||       d{   c g | _         S  7 B7 # t        $ rp}t        |      | j                  j                  v rD|}| j                  j                          d{  7   t        j                  d       d{  7   n Y d}~d}~ww xY w# g | _         w xY ww)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)r  r  rR  )r  rA  r  rd   rb   r   _executer   r6  r   rF  r   r   rU  )r   r  r  rK  rM  r  s         rU   executezClusterPipeline.execute  s    $ ""I	%4<<DDE <<++,,11333!%++'5+=	 "/ "  & #%D1, O) 4 % Aw$.."C"CC$%	"ll11333%mmD111  2 #%Ds   D6AD* 'B*(D* -,B.B,B.D* D6'D* ,B..	D'7A D"7C:8D"DD"D* "D''D* *	D33D6rW   stackr  c                 (  K   |D cg c]+  }|j                   rt        |j                   t              s*|- }}i }|D ]  }|j                  j	                  dd       }|r#|j                  |      s|j                  |      }	n? |j                  |j                  d|i d {   }	|	st        d|j                   d      t        |	      dkD  rt        d|j                         |	d   }
|
j                  |vr|
g f||
j                  <   ||
j                     d   j                  |        t        j                  d |j                         D          d {   }t!        |      r_|ra|D ]\  }t        |j                   t"        t$        t&        f      s)	  |j(                  |j                  i |j                   d {   |_         ^ |r|D ]  }|j                   }t        |t              s d	j+                  t-        t.        |j                              }d
|j0                  dz    d| d|j                   }|f|j                  dd  z   |_        | |j3                  |j5                         j                        }|G|d   D ]?  }t7        |j                         | j8                  j:                  v s/|j=                           n |D cg c]  }|j                    c}S c c}w 7 F7 7 -# t        $ r}||_         Y d }~d }~ww xY wc c}w w)Nr.  r  r:  r;  r   zToo many targets for command r   c              3   p   K   | ].  }t        j                  |d    j                  |d                0 yw)r   r   N)r   r=  r  r  s     rU   r@  z+ClusterPipeline._execute.<locals>.<genexpr>  s6       ##DG$<$<T!W$EFs   46r   z
Command #  (z) of pipeline caused error: )r  r0  rE  rY   r_   r2  r8  r"  r  r8   r  r   r   r   rC  r   anyr<   r7   r.   rN  r  maprC   positionr   r   r6  r   rF  rB  )r   r   r  r  r  r   todor7  rI  r.  r   errorsrM  r  r  msgr   s                    rU   r  zClusterPipeline._execute  s     !


jY6WC
 
  	,C ZZ^^NDANf&:&:>&J%99.I%<V%<%<XX&)7&   $/;CHH:[Q  < 1$+.KCHH:,VWW?Dyy%$(":dii $))Q&&s+#	,& ~~!LLN
 
 v;! +C!#**}j(.ST+/Ev/E/E!$0-0ZZ0 *CJ+  	%C ZZF!&)4"%((3x+B"C()9(:"WI F--3[[M;  (+fv{{12&>$	% !99V%<%<%>%C%CDL'
 (? C CJJ'4>>+L+LL335 ',,s

,,I
 
*  ) +)*CJJ+8 -s   L+K!K!A)L K&!B6LK)<L)K/?K, 	K/	%L/CL4LL	L)L,K//	L
8L?LL

Lr  r,  c                     | j                   j                  |      j                         D ]  } | j                  |g|   | S r   )r  _partition_keys_by_slotr   rN  )r   r  r,  	slot_keyss       rU   _split_command_across_slotsz+ClusterPipeline._split_command_across_slots,  sG     ==dCJJL 	6I D  595	6 rT   mappingc                 ,   | j                   j                  }i }|j                         D ]@  }t        |j	                  |d               }|j                  |g       j                  |       B |j                         D ]  } | j                  dg|   | S )Nr   MSET)	r  ri   r  r,   r	  
setdefaultextendr   rN  )r   r  ri   slots_pairspairr  pairss          rU   mset_nonatomiczClusterPipeline.mset_nonatomic4  s     ,,&&MMO 	:DGNN4734D""4,33D9	: !'') 	1E D  0%0	1 rT   )rZ   r]  rh  )TT)rO   rP   rQ   rk  rm  rW   r   r   r   r   r   r   r   r  r  rn  r  r(  r  r   r?   r>   rN  r   r  r  r1  r  r	   r=   r  rS   rT   rU   r]  r]  T  sF   "H .I:| : :
'!-9S$0A%AB -!)$ )( (4+,8;	( GK.%".%?C.%	c.%h  $#'K-K- %&K- 	K-
 !K- 
cK-Z#'	w
23	rT   r]  r   rK  r  c                   0    e Zd ZdedededdfdZdefdZy)r  r  r  rY   rZ   Nc                 <    || _         || _        || _        d | _        y r   )r  rY   r  r  )r   r  r  rY   s       rU   r   zPipelineCommand.__init__M  s    	 -1rT   c                 V    d| j                    d| j                   d| j                   dS )N[z] r  ))r  r  rY   r   s    rU   r  zPipelineCommand.__repr__S  s)    4==/DII;bQ??rT   )rO   rP   rQ   r(  r   r   r1  r  rS   rT   rU   r  r  L  s1    2 2S 2C 2D 2@# @rT   r  )br   r|  r   rz  rq  typingr   r   r   r   r   r   r	   r
   r   r   r   r   redis._parsersr   r   redis._parsers.helpersr   r   r   redis.asyncio.clientr   redis.asyncio.connectionr   r   r   r   redis.asyncio.lockr   redis.asyncio.retryr   redis.backoffr   redis.clientr   r   r   redis.clusterr    r!   r"   r#   r$   r%   r&   r'   r(   redis.commandsr)   r*   	redis.crcr+   r,   redis.credentialsr-   redis.exceptionsr.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   redis.typingr=   r>   r?   redis.utilsr@   rA   rB   rC   rD   r1  rE   rH   rW   rF   r   r]  r  replacelowersetattrr  rS   rT   rU   <module>r     sc           8 
 3 X X # % ) D D
 
 
 D 8 0    " 3 2  C](;T#}BT=U
M u
="68Q u
p_ _D[ [|mm%9;T m` ) GGooc3'--/G""OW&<W&EFG@ @rT   