+
     h  c            	       s   ^ RI t ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIHtHtH	t	H
t
HtHtHtHtHtHtHtHt ^ RIHtHt ^ RIHtHtHt ^ RIHt ^ RIHtHtHtH t  ^ RI!H"t" ^ RI#H$t$ ^ R	I%H&t& ^ R
I'H(t(H)t)H*t* ^ RI+H,t,H-t-H.t.H/t/H0t0H1t1H2t2H3t3H4t4 ^ RI5H6t6H7t7 ^ RI8H9t9H:t: ^ RI;H<t< ^ RI=H>t>H?t?H@t@HAtAHBtBHCtCHDtDHEtEHFtFHGtGHHtHHItIHJtJHKtKHLtL ^ RIMHNtNHOtOHPtP ^ RIQHRtRHStSHTtTHUtUHVtV ]! R]WR]R,          ]
]R3,          4      tX ! R R]4      tY ! R R]*]0]74      tZ ! R R4      t[ ! R R4      t\ ! R R]*]0]74      t]], F<  t^]^P                  RR4      P                  4       t^]^R8X  d   K,  ]a! ]]]^]2! ]^4      4       K>  	   ! R  R!4      tbR# )"    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                   sT    ] tR t^Ot]! ]P                  R]R]R]	R]
R]R]/4      tRtR# )	ClusterParserZASKZCLUSTERDOWNZ	CROSSSLOTZ
MASTERDOWNZMOVEDZTRYAGAIN N)__name__
__module____qualname____firstlineno__r?   r   ZEXCEPTION_CLASSESr,   r/   r.   r3   r5   r:   __static_attributes__rF       :/usr/lib/python3.14/site-packages/redis/asyncio/cluster.pyrE   rE   O   s;    "''8+./Z	

rL   rE   c            &       s4  a  ] tR t^]t o Rt]V 3R lR l4       tRQtRRRRR^^^RR^ RRRRRR]! 4       R	R
R^ RRRRRRRRRRRRRRR^R3&V 3R lR llt	V 3R lR lt
V 3R lR lt]! RRRR7      V 3R lR l4       tV 3R lR ltV 3R lR ltV 3R lR ltRt]P&                  ]P*                  3V 3R lR  lltV 3R! lR" ltV 3R# lR$ ltV 3R% lR& ltV 3R' lR( ltV 3R) lR* ltV 3R+ lR, ltV 3R- lR. ltRSV 3R/ lR0 lltRTV 3R1 lR2 lltV 3R3 lR4 lt V 3R5 lR6 lt!V 3R7 lR8 lt"V 3R9 lR: lt#V 3R; lR< lt$V 3R= lR> lt%R?R/V 3R@ lRA llt&V 3RB lRC lt'V 3RD lRE lt(V 3RF lRG lt)V 3RH lRI lt*V 3RJ lRK lt+RUV 3RL lRM llt,RVV 3RN lRO llt-RPt.V t/R# )WRedisClustera/  
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

c                *   < V ^8  d   QhRS[ RS[RR/# )   urlkwargsreturnrN   )strr   Zformat__classdict__   "rM   __annotate__RedisCluster.__annotate__   s"      3 # . rL   c                s    VP                  \        V4      4       VP                  RR4      \        J d   RVR&   V ! R/ VB # )aI  
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sslrF   )updater   popr   )ZclsrQ   rR      &&,rM   from_urlZRedisCluster.from_url   s=    8 	in%::($/=@ F5M}V}rL   Ni  TFzredis-pyzutf-8ZstrictZrequiredc          Q      s>  < V ^8  d   QhRS[ S[,          RS[S[S[3,          RS[ S[R,          ,          RS[RS[RS[RS[R	S[R
S[RS[S[S[3,          RS[ S[,          RS[ S[,          RS[ S[,          RS[ S[,          RS[ S[,          RS[ S[,          RS[ S[,          RS[RS[RS[RS[RS[ S[,          RS[RS[ S[S[S[S[S[	3,          3,          ,          RS[ S[,          RS[ R,          RS[ S[S[
S[,          ,          ,          RS[RS[ S[,          R S[ S[,          R!S[R"S[ S[,          R#S[R$S[ S[,          R%S[ S[P                  ,          R&S[ S[,          R'S[ S[,          R(S[ S[S[S[S[3,          .S[S[S[3,          3,          ,          R)R*/'# )+rP   hostportstartup_nodesrD   require_full_coverageread_from_replicasreinitialize_stepscluster_error_retry_attemptsconnection_error_retry_attempts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ssl_min_versionssl_ciphersprotocoladdress_remaprS   N)r   rT   r   intr   boolr+   floatr   Zbytesr
   	Exceptionr[   Z
TLSVersionr   r	   rU   rW   rM   rX   rY      s    e2 e2sme2 CHoe2
  ] 34e2  $e2 !e2  e2 '*e2 *-e2 e2 #s(Oe2 sme2 &&89e2  3-!e2" 3-#e2$ c]%e2& 3-'e2( c])e2, -e2. /e20 1e24  %5e26 !)7e28 9e2: #+73c5j8I3I+J"K;e2< !=e2>  ?e2@ !d9o!67Ae2D Ee2F smGe2H c]Ie2J Ke2L smMe2N !Oe2P c]Qe2R "#..1Se2T c]Ue2V 3-We2X  %S/):E#s(O)K LMYe2Z 
[e2rL   c'                s   V
'       d   \        R 4      hV'       d   \        R4      hV'       d	   V'       g   V'       g   \        R4      h/ RV	bR\        bR\        bRVbRVbRVbR	VbR
VbRVbRVbRVbRVbRVbRVbRVbRVbRVbRVRV%/Cp'V'       d(   V'P                  R\        RVRVRVRV RV!RV"RV#RV$/	4       V'       d   V P
                  V'R&   VV n        V'       g   V'       g   V^ 8  dp   T;'       g    \        \        4       V4      V n        V'       g   \        \        .pV P                  P                  V4       V'P                  RV P                  /4       \        P                  ! 4       V'R&   V'P                  R4      R%9   d   V'R,          P                  \        4       MV'R,          P                  \         4       V'V n        V'       dI   . p(V F=  p)V(P%                  \'        V)P(                  V)P*                  3/ V P"                  B 4       K?  	  T(pM. pV'       d.   V'       d&   VP%                  \'        W3/ V P"                  B 4       \-        VVV'V&R 7      V n        \1        VVV4      V n        WPn        W`n        Wpn        Wn        ^ V n        \?        4       V n         V PB                  PD                  P                  4       V n#        V PB                  PH                  P                  4       V n%        V'R,          V n&        V PB                  PN                  P                  4       V n(        R! V PP                  R"&   R#V n)        R$V n*        R$# )&z/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)])rh   rZ   Zparser_classrk   rl   rm   rn   ro   rp   rq   rr   rs   rt   ru   rv   rw   rx   ry   r   r{   r|   r}   r~   r   r   r   r   Zredis_connect_funcresponse_callbacksr   c                 sV    \        \        VP                  4       4      ^ ,          3/ VB # )r    )r&   listvalues)cmdresrR   r^   rM   Z<lambda>Z'RedisCluster.__init__.<locals>.<lambda>  s%    ':SZZ\"1%()/(rL   CLUSTER SLOTSTN)Z3   )+r6   r   rE   r\   r   
on_connectry   r   r   r1   r9   Zupdate_supported_errorsr   Zcopygetr   r   connection_kwargsappendrD   r`   ra   NodesManagernodes_managerr   encoderrd   re   rf   rg   reinitialize_counterr   commands_parser	__class__Z
NODE_FLAGS
node_flagsZCOMMAND_FLAGScommand_flagsr   ZRESULT_CALLBACKSresult_callbacks_initialize_lock)*selfr`   ra   rb   rc   rd   re   rf   rg   rh   ri   rj   rk   rl   rm   rn   ro   rp   rq   rr   rs   rt   ru   rv   rw   rx   ry   rz   r[   r{   r|   r}   r~   r   r   r   r   r   r   rR   Zpassed_nodesnodes*   &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&   rM   __init__ZRedisCluster.__init__   s   \ 'A  'E  D-'S "
"

"
 M"

 "#6"
 "
 "
 ;"
 "
 ;"
 "
 "
  0"
  $%:!"
" %&<#"
$  0%"
& '(@'"
( n)"
* U-"
2 MM&"L!;#]"L(*<!;%!;
 +/??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  T!R4;Q;Q!RS)!'	
 x:JK"4"4,H)/N,$%!24..3388:!^^99>>@"()="> $ ? ? D D F 	o.  -1
rL   c                   < V ^8  d   QhRR/# rP   rS   rN   rF   rU   rW   rM   rX   rY     s      . rL   c                s  "   V P                   '       d   V P                  '       g   \        P                  ! 4       V n        V P                  ;_uu_4       GRj  xL
  V P                   '       db    V P                  P                  4       G Rj  xL
  V P                  P                  V P                  P                  4      G Rj  xL
  RV n         RRR4      GRj  xL
  V # V #  L LX L#  \         dJ    T P                  P                  4       G Rj  xL 
  T P                  P                  R4      G Rj  xL 
  h i ; i Le  + GRj  xL 
 '       g   i     T # ; i5i)zJGet all nodes from startup nodes & creates connections if not initialized.NFrb   )
r   r   asyncior   r   
initializer   default_nodeBaseExceptionacloser      &rM   r   ZRedisCluster.initialize  s    :::$\\^
zzzz###	"00;;==="22== ..;;   ,1( "z t " > ) "0077999"0077HHH "zzz s   $E!2E!C%E!E1C+C'6C+C)C+E!E	E!'C+)C++(D?D
#D?7D:
8D??EE!E	
E
E	E		E!c                r   rP   rS   NrF   rU   rW   rM   rX   rY     s     	E 	Ed 	ErL   c                s  "   V P                   '       g   V P                  '       g   \        P                  ! 4       V n        V P                  ;_uu_4       GRj  xL
  V P                   '       gM   RV n         V P                  P                  4       G Rj  xL
  V P                  P                  R4      G Rj  xL
  RRR4      GRj  xL
  R# R#  Lv L= L L  + GRj  xL 
 '       g   i     R# ; i5i)z.Close all connections & client if initialized.NTrb   )r   r   r   r   r   r   r   r   rM   r   ZRedisCluster.aclose  s     :::$\\^
zzzz''''+D$,,33555,,33ODDD	 "zz   " 6D	 "zzzsv   $C52C5CC57CC"C7C8C<C5C	C5CCC5C2	C!
C2	*C2	,	C5z5.0.0zUse aclose() insteadclose)ZversionZreasonnamec                r   r   rF   rU   rW   rM   rX   rY     s      T rL   c                sB   "   V P                  4       G Rj  xL
  R#  L5i)z.alias for aclose() for backwards compatibilityNr   r   r   rM   r   ZRedisCluster.close  s      kkm   c                r   r   rF   rU   rW   rM   rX   rY     s     ' '. 'rL   c                >   "   V P                  4       G R j  xL
 #  L5iNr   r   r   rM   
__aenter__ZRedisCluster.__aenter__       __&&&&   c                *   < V ^8  d   QhRRRRRRRR/# rP   exc_typeN	exc_value	tracebackrS   rF   rU   rW   rM   rX   rY     s*        $ SW rL   c                sB   "   V P                  4       G R j  xL
  R #  L5ir   r   r   r   r   r      &&&&rM   	__aexit__ZRedisCluster.__aexit__  s     kkmr   c                6   < V ^8  d   QhRS[ S[RR3,          /# )rP   rS   NrN   r   r   rU   rW   rM   rX   rY     s      - -9S$%>? -rL   c                >    V P                  4       P                  4       # r   r   	__await__r   r   rM   r   ZRedisCluster.__await__       **,,rL   zUnclosed RedisCluster clientc                *   < V ^8  d   QhRS[ RS[ RR/# rP   _warn_grlrS   Nr   rU   rW   rM   rX   rY     s)        
	rL   c                s   \        V R 4      '       d]   V P                  '       gI   V! V P                   RV : 2\        V R7        RV RV P                  /pV! 4       P	                  V4       R# R# R#   \
         d     R# i ; i)r    ZsourceclientmessageN)Zhasattrr   _DEL_MESSAGEResourceWarningcall_exception_handlerRuntimeError)r   r   r   contexts   &&& rM   __del__ZRedisCluster.__del__  s    
 4''0@0@0@T&&'q1?4P#T9d6G6GH--g6	 1A'
   s   &A1 1B ?B c                $   < V ^8  d   QhRS[ RR/# )rP   
connectionrS   Nr   rU   rW   rM   rX   rY     s     
= 
=: 
=$ 
=rL   c                s   "   VP                  4       G R j  xL
  VP                  R4      G R j  xL
  \        VP                  4       G R j  xL
 4      R8w  d   \	        R4      hR #  LP L9 L5i)NZREADONLYZOKzREADONLY command failed)r   Zsend_commandrB   read_responser1   r   r      &&rM   r   ZRedisCluster.on_connect  se     ##%%% %%j111j66889TA!";<< B 	& 	28s1   A-A'A-A)A-A+A-)A-+A-c                .   < V ^8  d   QhRS[ R,          /# rP   rS   rD   r   rU   rW   rM   rX   rY     s     = =4. =rL   c                s\    \        V P                  P                  P                  4       4      # )zGet all nodes of the cluster.)r   r   nodes_cacher   r   r   rM   	get_nodesZRedisCluster.get_nodes  s"    D&&2299;<<rL   c                r   r   r   rU   rW   rM   rX   rY     s     D DtM2 DrL   c                @    V P                   P                  \        4      # )z%Get the primary nodes of the cluster.)r   get_nodes_by_server_typer   r   r   rM   get_primariesZRedisCluster.get_primaries      !!::7CCrL   c                r   r   r   rU   rW   rM   rX   rY     s     D Dd=1 DrL   c                r   )z%Get the replica nodes of the cluster.)r   r   r    r   r   rM   get_replicasZRedisCluster.get_replicas  r   rL   c                r   r   rF   rU   rW   rM   rX   rY     s     L L LrL   c                s    \         P                  ! \        V P                  P                  P                  4       4      4      # )z!Get a random node of the cluster.)randomchoicer   r   r   r   r   r   rM   get_random_nodeZRedisCluster.get_random_node  s+    }}T$"4"4"@"@"G"G"IJKKrL   c                r   r   rF   rU   rW   rM   rX   rY     s     / /- /rL   c                s.    V P                   P                  # )z#Get the default node of the client.)r   r   r   r   rM   get_default_nodeZRedisCluster.get_default_node  s    !!...rL   c                "   < V ^8  d   QhRRRR/# )rP   r   rD   rS   NrF   rU   rW   rM   rX   rY     s     	/ 	/] 	/t 	/rL   c                s    V'       d#   V P                  VP                  R7      '       g   \        R4      hWP                  n        R# )zn
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   r2   r   r   )r   r   r   rM   set_default_nodeZRedisCluster.set_default_node  s3     4==499===OPP*.'rL   c          	      p   < V ^8  d   QhRS[ S[,          RS[ S[,          RS[ S[,          RS[ R,          /# rP   r`   ra   r   rS   rD   r   rT   r   rU   rW   rM   rX   rY     sJ     B BsmB smB C=	B
 
-	 BrL   c                s:    V P                   P                  WV4      # )z&Get node by (host, port) or node_name.)r   r   r   r`   ra   r   r   rM   r   ZRedisCluster.get_node  s     !!**4yAArL   c                s:   < V ^8  d   QhRS[ RS[RS[R,          /# )rP   keyreplicarS   rD   )rT   r   r   rU   rW   rM   rX   rY     s*     $ $$!%$	-	 $rL   c                s.   V P                  V4      pV P                  P                  P                  V4      pV'       g   \	        RV R24      hV'       d8   \        V P                  P                  V,          4      ^8  d   R# ^pWE,          # ^ pWE,          # )a  
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)keyslotr   slots_cacher   r8   len)r   r   r   slotZ
slot_cachenode_idx   &&&   rM   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##rL   c                &   < V ^8  d   QhRS[ RS[/# )rP   r   rS   )r<   r   rU   rW   rM   rX   rY     s     2 2: 2# 2rL   c                sJ    \        V P                  P                  V4      4      # )zk
Find the keyslot for a given key.

See: https://redis.io/docs/manual/scaling/#redis-cluster-data-sharding
)r*   r   encode)r   r   r   rM   r   ZRedisCluster.keyslot  s     ++C011rL   c                    < V ^8  d   QhRS[ /# rP   rS   )r   rU   rW   rM   rX   rY     s      W rL   c                    V P                   # )z%Get the encoder object of the client.)r   r   r   rM   get_encoderZRedisCluster.get_encoder  s    ||rL   c                sF   < V ^8  d   QhRS[ S[S[S[,          3,          /# r   )r   rT   r   r   rU   rW   rM   rX   rY   "  s"     & &tC#,>'? &rL   c                r   )zGGet the kwargs passed to :class:`~redis.asyncio.connection.Connection`.)r   r   r   rM   get_connection_kwargsZ"RedisCluster.get_connection_kwargs"  s    %%%rL   c                r   )rP   rS   r   )r   rU   rW   rM   rX   rY   &  s      8G, rL   c                r   r   )ry   r   r   rM   	get_retryZRedisCluster.get_retry&  s    zzrL   c                r   )rP   ry   r   rS   NrF   rU   rW   rM   rX   rY   )  s     # #w #4 #rL   c                s    Wn         V P                  4        F9  pVP                  P                  R V/4       VP                   F	  pWn         K  	  K;  	  R# )ry   N)ry   r   r   r\   _connections)r   ry   r   Zconns   &&  rM   	set_retryZRedisCluster.set_retry)  sF    
NN$D""))7E*:;))"
 * %rL   c                rO   )rP   commandcallbackrS   N)rT   r   rU   rW   rM   rX   rY   0  s$     4 4S 4<M 4RV 4rL   c                s"    W P                   V&   R# )zSet a custom response callback.N)r   )r   r  r     &&&rM   set_response_callbackZ"RedisCluster.set_response_callback0  s    +3(rL   	node_flagc          	      sP   < V ^8  d   QhRS[ RS[RS[S[ ,          RS[R,          /# )rP   r  argsr	  rS   rD   )rT   r   r   r   rU   rW   rM   rX   rY   4  s6      
  
 
#& 
3;C= 
	m	 
rL   c               s  "   V'       g   V P                   P                  V4      pW P                  9   EdG   W P                  P                  8X  d   V P
                  P                  .# W P                  P                  8X  d    V P
                  P                  \        4      # W P                  P                  8X  d    V P
                  P                  \        4      # W P                  P                  8X  d.   \        V P
                  P                  P                  4       4      # W P                  P                   8X  dC   \"        P$                  ! \        V P
                  P                  P                  4       4      4      .# V P
                  P'                  V P(                  ! V.VO5!  G R j  xL
 V P*                  ;'       d
    V\,        9   4      .#  L%5ir   )r   r   r   r   ZDEFAULT_NODEr   r   Z	PRIMARIESr   r   ZREPLICASr    Z	ALL_NODESr   r   r   ZRANDOMr   r   get_node_from_slot_determine_slotrd   r'   )r   r  r	  r
  s   &&$*rM   _determine_nodesZRedisCluster._determine_nodes4  sX    
 **..w7I'NN777**7788NN444))BB7KKNN333))BB7KKNN444D..::AACDDNN111d4+=+=+I+I+P+P+R&STUU 11**7:T::''DDG},D
 	
:s   F'G)G*G Gc                s,   < V ^8  d   QhRS[ RS[RS[/# )rP   r  r
  rS   )rT   r   r   rU   rW   rM   rX   rY   V  s"     1 1S 1 1 1rL   c                s4  "   V P                   P                  V4      \        8X  d   \        V^ ,          4      # VP	                  4       R9   dc   \        V4      ^8  d   \        RV.VO5 24      hV^^\        V^,          4      ,            pV'       g   \        P                  ! ^ \        4      # MlV P                  P                  ! V.VO5!  G Rj  xL
 pV'       g?   VP	                  4       R9   d   \        P                  ! ^ \        4      # \        RV 24      h\        V4      ^8X  d   V P                  V^ ,          4      # V Uu0 uF  q@P                  V4      kK  	  pp\        V4      ^8w  d   \        V R24      hVP                  4       #  Lu upi 5i)r    zInvalid args in command: NzNo 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)ZEVALZEVALSHA)ZFCALLZFCALL_RO)r   r   r!   r   Zupperr   r6   r   Z	randranger)   r   Zget_keysr   r]   )r   r  r
  keysr   Zslotss   &&*   rM   r  ZRedisCluster._determine_slotV  s|    !!'*g5tAw< ==?114y1}+/$/?@  ADG,-D ''+CDD  --66wFFFD ==?&;;!++A/GHH+//3f6  t9><<Q(( /33dsc"d3u:?')DE  yy{1 G$ 4s+   CFFFA*FF!1FFc                r   )rP   target_nodesrS   r   r   rU   rW   rM   rX   rY     s     Q Q# Q$ QrL   c                sN    \        V\        4      ;'       d    WP                  9   # r   )
isinstancerT   r   )r   r  r   rM   _is_node_flagZRedisCluster._is_node_flag  s    ,,PP1PPrL   c                4   < V ^8  d   QhRS[ RS[R,          /# )rP   r  rS   rD   )r   r   rU   rW   rM   rX   rY     s        ]8K rL   c                s    \        V\        4      '       d   TpV# \        V\        4      '       d   V.pV# \        V\        4      '       d   \        VP	                  4       4      pV# \        R \        V4       24      h)ztarget_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   rD   dictr   	TypeErrortype)r   r  nodes   && rM   _parse_target_nodesZ RedisCluster._parse_target_nodes  s    lD)) E   k22!NE  d++ ,,./E  & '+<&8%9; rL   c                s,   < V ^8  d   QhRS[ RS[RS[/# rP   r
  rR   rS   )r<   r   rU   rW   rM   rX   rY     s'     R R: R R RrL   c           
     s&  a aa"   S^ ,          p. pRpS P                   pSP                  RR4      pV'       d-   S P                  V4      '       g   S P                  V4      pRp^ p^V,           p\	        V4       EF  p	S P
                  '       dU   S P                  4       G Rj  xL
  \        V4      ^8X  d-   V^ ,          S P                  4       8X  d   S P                  4         V'       g2   S P                  ! SRV/ G Rj  xL
 pV'       g   \        RS R24      h\        V4      ^8X  dj   S P                  ! V^ ,          .SO5/ SB G Rj  xL
 p
VS P                  9   d0   S P                  V,          ! W4^ ,          P                  V
/3/ SB u # V
u # V Uu. uF  qP                  NK  	  pp\        P                   ! VVV 3R lV 4       !  G Rj  xL
 pVS P                  9   d0   S P                  V,          ! V\#        \%        W4      4      3/ SB u # \#        \%        W4      4      u # 	  R#  EL EL4 Lu upi  Lk  \&         dC   pT^ 8  d5   \)        T4      S P*                  P,                  9   d   T^,          p Rp?EK  ThRp?ii ; i5i)	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
Fr  NTr	  !No targets were found to execute  command onc              3   sx   <"   T F/  p\         P                  ! SP                  ! V.SO5/ SB 4      x  K1  	  R # 5ir   )r   create_task_execute_command).0r   r
  rR   r   s   & rM   	<genexpr>Z/RedisCluster.execute_command.<locals>.<genexpr>  sD       )5 $// $ 5 5d LT LV L  )5s   7:)rf   r]   r  r  ranger   r   r   r   replace_default_noder  r6   r  r   r   r   gatherr  Zzipr   r  r   ERRORS_ALLOW_RETRY)r   r
  rR   r  r  Ztarget_nodes_specifiedZretry_attemptspassed_targetsZexecute_attempts_retr   r  r   es   fjl            rM   execute_commandZRedisCluster.execute_command  ss    $ q'!&::ND9$"4"4^"D"D33NCL%)"N ~-'(Aoo'''%*$Q4+@+@+BB --/*-)-)>)>*)7* $L (3?v[Q  |$) $ 5 5l1o W WPV WWC$"7"77#44W=#1o&:&:C%@ DJ   J2>?,$II,D?#*>> )5	$ F $"7"77#44W=#T#d*;%< @F    D 122U )'$ X @  !A%$q'T^^5V5V*V #a'N Gs   A
JAJ"H2#A J$I,IH5I?IH8AIJIJIH:.%IH?AIJI+J5I8I:IJ4J	 JJ		JJc                sF   < V ^8  d   QhRRRS[ S[S[3,          RS[RS[/# )rP   target_noderD   r
  rR   rS   r   r=   r<   r   rU   rW   rM   rX   rY     s=     F- F-(F-16tZ7G1HF-TWF-	F-rL   c                s^  "   R ;rERpV P                   pV^ 8  d   V^,          p V'       d/   V P                  VR7      pVP                  R4      G Rj  xL
  R pM_V'       dX   V P                  ! V!  G Rj  xL
 pV P                  P                  YP                  ;'       d    V^ ,          \        9   4      pR pVP                  ! V/ VB G Rj  xL
 # \9        R4      h L Lj L  \        \        3 d    h \        \        3 dL    T P                  P                  P                  TP                  R4       T P                  4       G Rj  xL 
  h \          d;    T P                  4       G Rj  xL 
  \"        P$                  ! R4      G Rj  xL 
  h \&         d   p	T ;P(                  ^,          un        T P*                  '       dD   T P(                  T P*                  ,          ^ 8X  d"   T P                  4       G Rj  xL 
  ^ T n        MYP                  n        Rp Rp	?	EK  Rp	?	i\.         d0   p	\1        T	P2                  T	P4                  R7      pRp Rp	?	EKI  Rp	?	i\6         d@    YpP                   ^,          8  d$   \"        P$                  ! R4      G Rj  xL 
   EK   EK  i ; i5i)	FNr   ZASKING      ?Tr`   ra   g?zTTL exhausted.)ZRedisClusterRequestTTLr   r)  r  r   r  rd   r'   r-   r4   r1   r9   rb   r]   r   r   r/   r   sleepr5   r   re   _moved_exceptionr,   r%   r`   ra   r:   r0   )
r   r*  r
  rR   ZaskingZmovedZredirect_addrZttlr   r(  s
   &&*,      rM   r  ZRedisCluster._execute_command  s.     ))Ag1HC;."&----"HK%55h???"F "&!5!5t!<<D"&"4"4"G"G55RR$q']:R#K "E(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-:;&&7  -166 G  .44q88!----- 9.s   "J-C% &C% CC% #C% 6C!7+C% #,C% C#C% J-C% !C% #C% % J*AJ*
EJ*J*.E1/J*FJ*J*A H%>H?H%J-%J*2J*3#IJ-J**1J*JJ*!J-)J**J-c                sJ   < V ^8  d   QhRS[ S[,          RS[ S[,          RR/# )rP   transaction
shard_hintrS   ClusterPipeline)r   r   rU   rW   rM   rX   rY   <  s-     % %#C=%=Ec]%	%rL   c                sd    V'       d   \        R4      hV'       d   \        R4      h\        V 4      # )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)r6   r2  )r   r0  r1  r  rM   pipelineZRedisCluster.pipeline<  s-     '(RSS'(STTt$$rL   c                s   < V ^8  d   QhRS[ RS[S[,          RS[RS[RS[S[,          RS[S[S[,          ,          RS[RS[/# )	rP   r   timeoutr.  blockingblocking_timeout
lock_classthread_localrS   )r=   r   r   r   r
   r   rU   rW   rM   rX   rY   N  sv     H
 H
H
 %H
 	H

 H
 #5/H
 T$Z(H
 H
 
H
rL   c           
     s4    Vf   \         pV! V VVVVVVR7      # )a	  
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.)r4  r.  r5  r6  r8  r   )r   r   r4  r.  r5  r6  r7  r8  s   &&&&&&&&rM   lockZRedisCluster.lockN  s2    | J-%
 	
rL   )r   r   rf   r   r   rg   r   r   r   r   rd   r   re   r   r   ry   )r   r   rf   r   r   rg   r   r   r   r   rd   r   re   r   r           NNNF)NN)Ng?TNNT)0rG   rH   rI   rJ   __doc__Zclassmethodr_   	__slots__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  r3  r9  rK   __classdictcell__rV      @rM   rN   rN   ]   s+    Qf  @I( # $7;&*#("#,-/0$"<@"&"&%)",%4%6'!&'(26!&NR*.#':>&*%)'&*#(%)48%)"#PTYe2 e2N &	E 	E 1GgV W' ' - - 2L ]],, 
= 
== =D DD DL L/ /	/ 	/B B$ $82 2 & & # #4 4 
CG 
  
D1 1fQ Q (R RhF- F-P% %$H
 H
 H
rL   rN   c                   s  a  ] tR tRt o RtRtRRRR]/V 3R lR llltV 3R lR	 ltV 3R
 lR lt	Rt
]P                  ]P                  3V 3R lR lltV 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltRtV tR# )rD   i  z
Create a new ClusterNode.

Each ClusterNode manages multiple :class:`~redis.asyncio.connection.Connection`
objects for the (host, port).
rZ   rh   Nc                sx   < V ^8  d   QhRS[ RS[S[ S[3,          RS[S[ ,          RS[RS[S[,          RS[RR/# )	rP   r`   ra   server_typerh   rZ   r   rS   N)rT   r   r   r   r
   r   r   rU   rW   rM   rX   ClusterNode.__annotate__  sk     W WW CHoW c]	W W z*W !W 
WrL   c               s@   VR 8X  d   \         P                  ! V4      pWR&   W&R&   Wn        W n        \	        W4      V n        W0n        W@n        WPn        W`n	        VP                  R/ 4      V n        . V n        \        P                  ! V P                  R7      V n        R# )	localhostr`   ra   r   )ZmaxlenN)socketgethostbynamer`   ra   r%   r   rE  rh   rZ   r   r]   r   r  collectionsZdeque_free)r   r`   ra   rE  rh   rZ   r   s   &&&&$$,rM   r   ZClusterNode.__init__  s     ;''-D$(&!$(&!		!$-	&. 0!2"3"7"78Lb"Q.0(3(9(9AUAU(V
rL   c                r   r   rT   rU   rW   rM   rX   rF    s     
 
# 
rL   c           	     sp    R V P                    RV P                   RV P                   RV P                   R2	# )z[host=z, port=z, name=z, server_type=Z])r`   ra   r   rE  r   r   rM   __repr__ZClusterNode.__repr__  s?    TYYKwtyyk 2II;nT-=-=,>aA	
rL   c                r   )rP   objrS   r  rU   rW   rM   rX   rF    s     F F# F$ FrL   c                sd    \        V\        4      ;'       d    VP                  V P                  8H  # r   )r  rD   r   )r   rN  r   rM   __eq__ZClusterNode.__eq__  s$    #{+EEDII0EErL   zUnclosed ClusterNode objectc                r   r   r   rU   rW   rM   rX   rF    s)        
	rL   c                s   V P                    F^  pVP                  '       g   K  V! V P                   R V : 2\        V R7        RV RV P                  /pV! 4       P	                  V4        R# 	  R#   \
         d     Li ; i)r   r   r   r   N)r  Zis_connectedr   r   r   r   )r   r   r   r   r      &&&  rM   r   ZClusterNode.__del__  s    
 ++J&&&**+1TH5tT'y$:K:KLGF11':  , $ s   &A11A?>A?c                r   r   rF   rU   rW   rM   rX   rF    s     
 
$ 
rL   c                s   "   \         P                  ! R  V P                   4       RR/ G Rj  xL
 p\        R V 4       R4      pV'       d   VhR#  L#5i)c              3   j   "   T F)  p\         P                  ! VP                  4       4      x  K+  	  R # 5ir   r   r  
disconnect)r  r      & rM   r   )ClusterNode.disconnect.<locals>.<genexpr>  s.      "3J ##J$9$9$;<<"3   13Zreturn_exceptionsTNc              3   sV   "   T F  p\        V\        4      '       g   K  Vx  K!  	  R # 5ir   )r  r   )r  r   rT  rM   r   rU    s     E3C*S)*DCC3s   )
))r   r#  r  Znext)r   r'  Zexcs   &  rM   rS  ZClusterNode.disconnect  s[     NN"&"3"3

 #
 
 E3EtLI 
s   +AA$Ac                r   r   r   rU   rW   rM   rX   rF    s     	( 	(J 	(rL   c                s(    V P                   P                  4       #   \         dk    \        T P                  4      T P
                  8  d<   T P                  ! R/ T P                  B pT P                  P                  T4       Tu # \        4       hi ; i)NrF   )
rK  Zpopleft
IndexErrorr   r  rh   rZ   r   r   r4   r   rT  rM   acquire_connectionZClusterNode.acquire_connection  s~    	(::%%'' 	(4$$%(<(<<!22LT5K5KL
!!((4!!%''	(s    A(BBc                s2   < V ^8  d   QhRS[ RS[RS[RS[/# )rP   r   r  rR   rS   )r   rT   r   rU   rW   rM   rX   rF    s-      $/2>A	rL   c                s  "    \         V9   d1   VP                  R R7      G Rj  xL
 pVP                  \         4       MVP                  4       G Rj  xL
 p \        V9   d   VP                  \        4       VP                  RR4       W P
                  9   d   V P
                  V,          ! V3/ VB # V#  L Le  \         d    \        T9   d   T\        ,          u # h i ; i5i)T)Zdisable_decodingNr  )r   r   r]   r7   r   r   )r   r   r  rR   Zresponses   &&&, rM   parse_responseZClusterNode.parse_response  s     		v%!+!9!94!9!PP

<(!+!9!9!;; V#JJ~& 	

64  ---**73HGGG' Q < 	'n--	sU   C$ B: B6B: C$B: B8B: AC$6B: 8B: :#C!C$C!!C$c                s,   < V ^8  d   QhRS[ RS[ RS[ /# r  r   rU   rW   rM   rX   rF    s"     * *3 *# *# *rL   c                s>  "   V P                  4       pVP                  VP                  ! V!  R 4      G Rj  xL
   V P                  ! W1^ ,          3/ VB G Rj  xL
 V P                  P                  V4       #  LB L!  T P                  P                  T4       i ; i5i)FN)rX  send_packed_commandZpack_commandrY  rK  r   )r   r
  rR   r   s   &*, rM   r)  ZClusterNode.execute_command  s     ,,.
 ,,Z-D-Dd-KUSSS	*,,ZaKFKK JJj) 	T L JJj)s8   4BA9BA= A;A= B;A= =BBc                s4   < V ^8  d   QhRS[ R,          RS[/# )rP   commandsPipelineCommandrS   )r   r   rU   rW   rM   rX   rF  $  s!      t4E/F 4 rL   c                s  "   V P                  4       pVP                  VP                  R  V 4       4      R4      G Rj  xL
  RpV F?  p V P                  ! W$P                  ^ ,          3/ VP
                  B G Rj  xL
 Vn        KA  	  V P                  P                  V4       V#  Lh L,  \         d   pYTn        Rp Rp?K}  Rp?ii ; i5i)c              3   s8   "   T F  qP                   x  K  	  R # 5ir   )r
  )r  r   rT  rM   r   Z/ClusterNode.execute_pipeline.<locals>.<genexpr>*  s     $B#XXs   FNT)
rX  rZ  Zpack_commandsrY  r
  rR   resultr   rK  r   )r   r[  r   r'  r   r(  s   &&    rM   execute_pipelineZClusterNode.execute_pipeline$  s     ,,.
 ,,$$$B$BBE
 	
 	

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

*%
%	
  
sK   <CB'C1B+<B)=	B+"C)B++C	6C>CC		C)
r  rK  rZ   r   r`   rh   r   ra   r   rE  r   r:  )rG   rH   rI   rJ   r=  r>  r   r   rM  rO  r   r?  r@  r   rA  r   rS  rX  rY  r)  r^  rK   rB  rC  rD  rM   rD   rD     s     IW  %W .8W W8
 
F F 1L ]],,  
 
	( 	( 4* * rL   c                   s   a  ] tR tRt o RtRV 3R lR lltRV 3R lR lltRV 3R lR lltV 3R	 lR
 ltRV 3R lR llt	V 3R lR lt
V 3R lR ltRV 3R lR lltV 3R lR ltRtV tR# )r   i>  Nc                s   < V ^8  d   QhRS[ R,          RS[RS[S[S[3,          RS[S[S[S[S[3,          .S[S[S[3,          3,          ,          RR/# )rP   rb   rD   rc   r   r   rS   N)	r   r   r   rT   r   r   r   r	   r   rU   rW   rM   rX   NodesManager.__annotate__K  sl     1 1M*1  $1  S>	1
  %S/):E#s(O)K LM1 
1rL   c                s    V Uu/ uF  qUP                   VbK  	  upV n        W n        W0n        W@n        R V n        / V n        / V n        \        4       V n	        R V n
        R # u upi r   )r   rb   rc   r   r   r   r   r   r#   read_load_balancerr/  )r   rb   rc   r   r   r   s   &&&&& rM   r   ZNodesManager.__init__K  sd     ;HH-$iio-H%:"!2*+/57;="..,0 Is   A!c          	      r   r   r   rU   rW   rM   rX   r_  ]  sD      sm sm C=	
 
-	 rL   c                s   V'       dK   V'       dC   VR 8X  d   \         P                  ! V4      pV P                  P                  \	        WR7      4      # V'       d   V P                  P                  V4      # \        R4      h)rG  r-  zEget_node requires one of the following: 1. node name 2. host and port)rH  rI  r   r   r%   r2   r   r   rM   r   ZNodesManager.get_node]  si     D{"++D1##''4(KLL##''	22# rL   c                sX   < V ^8  d   QhRS[ S[R3,          RS[ S[R3,          RS[RR/# )rP   oldrD   new
remove_oldrS   N)r   rT   r   rU   rW   rM   rX   r_  q  sG      #}$% #}$% 	
 
rL   c                s   V'       d\   \        VP                  4       4       F>  pWB9  g   K  \        P                  ! VP	                  V4      P                  4       4      pK@  	  VP                  4        FG  w  rFWA9   d9   W,          VJ d   K  \        P                  ! W,          P                  4       4      pWaV&   KI  	  R # r   )r   r  r   r  r]   rS  items)r   ra  rb  rc  r   Ztaskr   s   &&&&   rM   	set_nodesZNodesManager.set_nodesq  s     SXXZ(?"..swwt}/G/G/IJD ) ))+JD{9$**39+?+?+ABI &rL   c                r   r   rF   rU   rW   rM   rX   r_    s     $% $%T $%rL   c                sn   V P                   pV P                  VP                  VP                  R 7      pV'       d"   VP                  \
        8w  d   \
        Vn        MX\        VP                  VP                  \
        3/ V P                  B pV P                  V P                  VP                  V/4       W P                  VP                  ,          9   d   V P                  VP                  ,          ^ ,          p\        Vn        V P                  VP                  ,          P                  V4       V P                  VP                  ,          P                  V4       W P                  VP                  ,          ^ &   V P                   V8X  d   W n        MV.V P                  VP                  &   RV n         R# )r-  N)r/  r   r`   ra   rE  r   rD   r   re  r   r   r   Zslot_idr    r   Zremover   )r   r(  Zredirected_nodeZold_primarys   &   rM   _update_moved_slotsZ NodesManager._update_moved_slots  sN   !!--QVV!&&-A**g5.5+ *+/+A+AO NN4++o.B.BO-TU..qyy99 **1995a8K '.K#QYY'..{; QYY'..?-<QYY'*  K/$3!
 ,;*;DQYY' $rL   c                rO   )rP   r   rd   rS   rD   )r   r   rU   rW   rM   rX   r_    s%      -1	rL   c                s   V P                   '       d   V P                  4         V'       du   V P                  V,          ^ ,          P                  pV P                  P                  V\        V P                  V,          4      4      pV P                  V,          V,          # V P                  V,          ^ ,          #   \        \        3 d    \        RT RT P                   R24      hi ; i)r    r   z5" not covered by the cluster. "require_full_coverage=Z")r/  rf  r   r   r`  Zget_server_indexr   rW  r  r8   rc   )r   r   rd   Zprimary_namer   rP  rM   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   B: A3B:  B: :.C(c                r  )rP   rE  rS   rD   )rT   r   rU   rW   rM   rX   r_    s      
 
C 
D<O 
rL   c                s    V P                   P                  4        Uu. uF  pVP                  V8X  g   K  VNK  	  up# u upi r   )r   r   rE  )r   rE  r   r  rM   r   Z%NodesManager.get_nodes_by_server_type  sH     ((//1
1;. D1
 	
 
s   >>c                r   r   rF   rU   rW   rM   rX   r_    s     ~% ~%$ ~%rL   c           
     s  "   V P                   P                  4        / p/ p. pR pR pRpV P                  P                  4        EF  p  VP	                  R4      G Rj  xL
 pRp\        T4      ^8X  dU   T^ ,          ^,          ^ ,          '       g8   \        T P                  4      ^8X  d   TP                  T^ ,          ^,          ^ &   T EFL  p
\        ^\        T
4      4       F&  pY,           Uu. uF  p\        T4      NK  	  upY&   K(  	  T
^,          pT^ ,          pTR8X  d   TP                  p\        T^,          4      pT P                  Y4      w  r. pTP                  \        Y4      4      pT'       g   \!        Y\"        3/ T P$                  B pTTTP&                  &   TP)                  T4       T
R,          pT F  pT^ ,          pT^,          pT P                  Y4      w  rTP                  \        Y4      4      pT'       g   \!        Y\*        3/ T P$                  B pTTTP&                  &   TP)                  T4       K  	  \        \        T
^ ,          4      \        T
^,          4      ^,           4       F  pY9  d   TY+&   K  Y+,          ^ ,          pTP&                  TP&                  8w  g   K;  TP)                  TP&                   RTP&                   RT 24       \        T4      ^8  g   Kz  \        R	R
P-                  T4       24      h	  EKO  	  Rp\        \.        4       F  pY9  g   K  R p M	  T'       g   EK   M	  V'       g   \        R\1        V4       24      VhV'       g2   V P2                  '       d    \        R\        V4       R\.         R24      hW n        V P7                  V P8                  VRR7       V P7                  V P                  V P8                  RR7       V P;                  \"        4      ^ ,          V n        RV n        R#  EL  \
         d    \        R4      hi ; i  \         d   p	T	p Rp	?	EK	  Rp	?	ii ; iu upi 5i)FNr   z(Cluster mode is not enabled on this nodeTZ :r   NNz vs z
 on slot: 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...)rc  ) r`  Zresetrb   r   r)  r7   r6   r   r   r`   r!  rB   r   remap_host_portr   r%   rD   r   r   r   r   r    joinr)   rT   rc   r   re  r   r   r   r/  )r   Ztmp_nodes_cacheZ	tmp_slotsZdisagreementsZstartup_nodes_reachableZfully_covered	exceptionZstartup_nodeZcluster_slotsr(  r   ZiZvalZprimary_noder`   ra   Znodes_for_slotr*  Zreplica_nodesZreplica_nodeZtarget_replica_nodeZtmp_slots   &                     rM   r   ZNodesManager.initialize  s.    %%'4646	"'	 ..557L*6*F*F*W$WM
 +/' M"a'%a(+A..**+q0)5):):a #A&%q#d),A<@GDGS|C0GDDG -#Aw#A2:',,D<?+!11$=
!#-11-2KL""-G#/3/E/E#K 5@ 0 01%%k2 $R$1L'?D'?D!%!5!5d!AJD*9*=*=mD>W*X'..9 /373I3I/+ ATO$7$<$<="))*=> %2 s47|Sa\A-=>A)'5	 $-<?#==K,<,<<)00#+==/k6F6F5GzRSQT U  #=1A5&;'448IIm4L3M%O'" !" ?I &n !M34%$)M 5 }w 8z ''''*9~&68  !;!;!; (Ky>"$'?&@ A  %t''TJt))4+;+;M !99'B1E $e %X$ /B 
   		, Es   AQ	PPP"P8$,QAQ0Q
F/Q8:Q7;Q7QQQ4QBQPP55P88QQQQQc                r   )rP   attrrS   NrL  rU   rW   rM   rX   r_  E  s     
 
 
 
rL   c                s   "   R V n         \        P                  ! R \        W4      P	                  4        4       !  G R j  xL
  R #  L5i)Nc              3   rQ  r   rR  r  r   rT  rM   r   Z&NodesManager.aclose.<locals>.<genexpr>H  s,      8D ##DOO$5668rV  )r   r   r#  Zgetattrr   )r   rj  r   rM   r   ZNodesManager.acloseE  s>      nn#D/668
 	
 	
s   =AA Ac                sB   < V ^8  d   QhRS[ RS[RS[S[ S[3,          /# )rP   r`   ra   rS   )rT   r   r	   rU   rW   rM   rX   r_  N  s*      C s uS#X rL   c                sP    V P                   '       d   V P                  W34      # W3# )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   r`   ra   r  rM   rg  ZNodesManager.remap_host_portN  s+     %%tl33zrL   )	r/  r   r   r   r   r`  rc   r   rb   )	r/  r   r   r   r`  rc   r   rb   r   r   r;  r<  )r   )rG   rH   rI   rJ   r>  r   r   re  rf  r  r   r   r   rg  rK   rB  rC  rD  rM   r   r   >  sj     
I1 1$ ( $$% $%L *
 
~% ~%@
 
 rL   r   c                   s,  a  ] tR tRt o RtR!tV 3R lR ltV 3R lR ltV 3R lR ltV 3R	 lR
 lt	V 3R lR lt
V 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltR"V 3R lR lltR"V 3R lR lltV 3R lR ltV 3R lR ltRtV tR # )#r2  iY  aG  
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
c                r   )rP   r   rS   N)rN   rU   rW   rM   rX   ClusterPipeline.__annotate__  s     : :| : :rL   c                s     Wn         . V n        R # r   _client_command_stack)r   r   r   rM   r   ZClusterPipeline.__init__  s    79rL   c                r   rP   rS   r2  rF   rU   rW   rM   rX   rl    s      "3 rL   c                s   "   V P                   P                  '       d#   V P                   P                  4       G R j  xL
  . V n        V #  L5ir   )rn  r   r   ro  r   r   rM   r   ZClusterPipeline.initialize  s=     <<###,,))+++  ,s   :AA
Ac                r   rp  rF   rU   rW   rM   rX   rl    s     ' '"3 'rL   c                r   r   r   r   r   rM   r   ZClusterPipeline.__aenter__  r   r   c                r   r   rF   rU   rW   rM   rX   rl    s*     ! ! ! !$ !SW !rL   c                s   "   . V n         R # 5ir   ro  r   r   rM   r   ZClusterPipeline.__aexit__  s      s   
c                r   )rP   rS   Nr2  r   rU   rW   rM   rX   rl    s!     - -9S$0A%AB -rL   c                r   r   r   r   r   rM   r   ZClusterPipeline.__await__  r   rL   c                r   rp  rF   rU   rW   rM   rX   rl    s      , rL   c                s    . V n         V # r   rq  r   r   rM   	__enter__ZClusterPipeline.__enter__  s     rL   c                r   r   rF   rU   rW   rM   rX   rl    s)     ! ! !$ !4 !D !rL   c                s    . V n         R # r   rq  r   r   rM   __exit__ZClusterPipeline.__exit__  s
     rL   c                r   r   )r   rU   rW   rM   rX   rl    s      $ rL   c                s    R# )z?Pipeline instances should  always evaluate to True on Python 3+TrF   r   r   rM   __bool__ZClusterPipeline.__bool__  s    rL   c                r   r   )r   rU   rW   rM   rX   rl    s     ( ( (rL   c                s,    \        V P                  4      # r   )r   ro  r   r   rM   __len__ZClusterPipeline.__len__  s    4&&''rL   c                s@   < V ^8  d   QhRS[ S[S[3,          RS[RR/# )rP   r
  rR   rS   r2  r+  rU   rW   rM   rX   rl    s/      4+,8;	rL   c                s|    V P                   P                  \        \        V P                   4      .VO5/ VB 4       V # )a$  
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
)ro  r   r\  r   )r   r
  rR   s   &*,rM   r)  ZClusterPipeline.execute_command  s<     	""C 3 34FtFvF	
 rL   c                s<   < V ^8  d   QhRS[ RS[ RS[S[,          /# )rP   raise_on_errorallow_redirectionsrS   )r   r   r   rU   rW   rM   rX   rl    s)     .% .%".%?C.%	c.%rL   c                s  "   V P                   '       g   . #  \        V P                  P                  4       Fz  pV P                  P                  '       d#   V P                  P                  4       G Rj  xL
   V P                  V P                  V P                   VVR7      G Rj  xL
 u . V n         # 	  Xh LC L  \         du   p\        T4      T P                  P                  9   dK   TpT P                  P                  4       G Rj  xL 
  \        P                  ! R4      G Rj  xL 
   Rp?K  h Rp?ii ; i  . T n         i ; i5i)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)rv  rw  r,  )ro  r!  rn  rf   r   r   _executer   r  r   r$  r   r   r.  )r   rv  rw  r&  r(  ri  r   rM   executeZClusterPipeline.execute  s    $ """I	%4<<DDE<<+++,,11333!%++'5+=	 "/ "  & #%D1 F, O) 4 % Aw$.."C"CC$%	"ll11333%mmD111  #%Ds   E	AD= 3B74D= 9,B;%B9&B;)D= +E	3D= 9B;;D:AD5	D
D5(D+)D5.D= 4D55D::D= =	EE	c                sT   < V ^8  d   QhRRRS[ R,          RS[RS[RS[ S[,          /# )rP   r   rN   stackr\  rv  rw  rS   )r   r   r   rU   rW   rM   rX   rl    sN     K- K-K- %&K- 	K-
 !K- 
cK-rL   c                s  "   V Uu. uF8  qUP                   '       d#   \        VP                   \        4      '       g   K6  VNK:  	  pp/ pV EF  pVP                  P	                  R R4      pV'       d*   VP                  V4      '       g   VP                  V4      p	MEVP                  ! VP                  RV/ G Rj  xL
 p	V	'       g   \        RVP                   R24      h\        V	4      ^8  d   \        RVP                   24      hV	^ ,          p
V
P                  V9  d   V
. 3WzP                  &   WzP                  ,          ^,          P                  V4       EK  	  \        P                  ! R VP                  4        4       !  G Rj  xL
 p\!        V4      '       Ed   V'       dk   V Fd  p\        VP                   \"        \$        \&        34      '       g   K0   VP(                  ! VP                  / VP                  B G Rj  xL
 Vn         Kf  	  V'       d   V F  pVP                   p\        V\        4      '       g   K'  RP+                  \-        \.        VP                  4      4      pRVP0                  ^,            R	V R
VP                   2pV3VP                  R,          ,           Vn        Vh	  VP3                  VP5                  4       P                  4      pVeQ   V^,           FC  p\7        VP                   4      V P8                  P:                  9   g   K3  VP=                  4         M	  V Uu. uF  qUP                   NK  	  up# u upi  EL EL ELU  \         d   pYn          Rp?EK  Rp?ii ; iu upi 5i)r  Nr	  r  r  zToo many targets for command c              3   s   "   T F8  p\         P                  ! V^ ,          P                  V^,          4      4      x  K:  	  R# 5i)r    N)r   r  r^  rk  rT  rM   r   Z+ClusterPipeline._execute.<locals>.<genexpr>  s8      *D ##DG$<$<T!W$EFF*s   A Ar   z
Command #  (z) of pipeline caused error: :i   NN)r]  r  r   rR   r]   r  r  r  r
  r6   r   r   r   r   r#  r   Zanyr:   r5   r,   r)  rh  ZmaprA   positionr   r   r  r   r$  r"  )r   r   rz  rv  rw  r   Ztodor  r%  r  r   Zerrorsr(  r]  r  Zmsgr   s   &&&&&            rM   rx  ZClusterPipeline._execute  s     !
 C


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

e,,I
 
*  ) +)*JJ+8 -s   N3MMAN
1N;M<NCNMN+-N)MM	MN$NCN"N:M?	NNMM<*M70N7M<<Nc                rO   )rP   r  r  rS   r2  )rT   r=   rU   rW   rM   rX   rl  2  s%      #'	rL   c                s    V P                   P                  V4      P                  4        F  pV P                  ! V.VO5!   K  	  V # r   )rn  Z_partition_keys_by_slotr   r)  )r   r  r  Z	slot_keyss   &&* rM   _split_command_across_slotsZ+ClusterPipeline._split_command_across_slots2  sA     ==dCJJLI  595 M rL   c                s:   < V ^8  d   QhRS[ S[S[3,          RR/# )rP   mappingrS   r2  )r   r;   r<   rU   rW   rM   rX   rl  :  s'      w
23	rL   c                s>   V P                   P                  p/ pVP                  4        FE  p\        VP	                  V^ ,          4      4      pVP                  V. 4      P                  V4       KG  	  VP                  4        F  pV P                  ! R.VO5!   K  	  V # )r    ZMSET)	rn  r   rd  r*   r   Z
setdefaultZextendr   r)  )r   r~  r   Zslots_pairsZpairr   Zpairss   &&     rM   mset_nonatomicZClusterPipeline.mset_nonatomic:  s     ,,&&MMODGNN4734D""4,33D9 $ !'')E  0%0 * rL   rm  N)ro  rn  )TT)rG   rH   rI   rJ   r=  r>  r   r   r   r   r   rr  rs  rt  ru  r)  ry  rx  r}  r  rK   rB  rC  rD  rM   r2  r2  Y  s     "H .I: :
 ' '! !- - ! ! ( ( &.% .%`K- K-Z  rL   r2  r   r&  r  c                   sD   a  ] tR tRt o V 3R lR ltV 3R lR ltRtV tR# )r\  iR  c                s0   < V ^8  d   QhRS[ RS[RS[RR/# )rP   r|  r
  rR   rS   N)r   r   rU   rW   rM   rX   PipelineCommand.__annotate__S  s)     2 2 2S 2C 2D 2rL   c                s8    W n         W0n        Wn        R V n        R # r   r
  rR   r|  r]  )r   r|  r
  rR   s   &&*,rM   r   ZPipelineCommand.__init__S  s    	 -1rL   c                r   r   rL  rU   rW   rM   rX   r  Y  s     @ @# @rL   c                sV    R V P                    RV P                   RV P                   R2# )Z[z] r{  Z))r|  r
  rR   r   r   rM   rM  ZPipelineCommand.__repr__Y  s)    4==/DII;bQ??rL   r  N)rG   rH   rI   rJ   r   rM  rK   rB  rC  rD  rM   r\  r\  R  s     2 2@ @rL   r\  )cr   rJ  r   rH  r[   r?  Ztypingr   r   r   r   r   r   r   r   r	   r
   r   r   Zredis._parsersr   r   Zredis._parsers.helpersr   r   r   Zredis.asyncio.clientr   Zredis.asyncio.connectionr   r   r   r   Zredis.asyncio.lockr   Zredis.asyncio.retryr   Zredis.backoffr   Zredis.clientr   r   r   Zredis.clusterr   r   r    r!   r"   r#   r$   r%   r&   Zredis.commandsr'   r(   Z	redis.crcr)   r*   Zredis.credentialsr+   Zredis.exceptionsr,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   Zredis.typingr;   r<   r=   Zredis.utilsr>   r?   r@   rA   rB   rT   rC   rE   rN   rD   r   r2  r  ZreplaceZlowerZsetattrr\  rF   rL   rM   <module>r     s_       
     8 
 3 X X # % ) D D
 
 
 D 8 0    " 3 2  C](;T#}BT=U
M y
="68Q y
xb bJX Xvnm%9;T nb )Gooc3'--/G""OW&<W&EF )@ @rL   