
    phh             	          S SK r S SKrS SKrS SKrS SKrS SKrS SKrS SKJrJ	r	  S SK
J
r
  S SKJr  S SKJrJrJrJrJrJrJrJrJrJrJrJrJrJr  S SKJrJr  S SKJ r J!r!J"r"  S SK#J$r$  S S	K%J&r&J'r'J(r(  S S
K)J*r*  S SK+J,r,  S SK-J.r.  S SK/J0r0J1r1  S SK2J3r3J4r4J5r5  S SK6J7r7J8r8J9r9J:r:J;r;J<r<J=r=J>r>J?r?J@r@  S SKAJBrBJCrC  S SKDJErEJFrF  S SKGJHrH  S SKIJJrJJKrK  S SKLJMrMJNrNJOrOJPrPJQrQJRrRJSrSJTrTJUrUJVrVJWrWJXrXJYrYJZrZJ[r[J\r\J]r]J^r^  S SK_J`r`JaraJbrb  S SKcJdrdJereJfrfJgrgJhrhJiriJjrj  \d(       a  S SKkJlrlJmrmJnrn  OSrlSrnSrm\" S\oS\S   \\S4   5      rp " S S\5\;\C5      rq " S S5      rr " S S5      rs " S S \5\;\C5      rt\7 H;  ru\uR                  S!S"5      R                  5       ru\uS#:X  a  M+  \x" \t\u\>" \u5      5        M=      " S$ S%5      ry " S& S'\5      rz " S( S)\z5      r{ " S* S+\{5      r| " S, S-\{5      r}g).    N)ABCabstractmethod)copy)chain)AnyCallable	CoroutineDequeDict	GeneratorListMappingOptionalSetTupleTypeTypeVarUnion)AsyncCommandsParserEncoder)_RedisCallbacks_RedisCallbacksRESP2_RedisCallbacksRESP3)ResponseCallbackT)
ConnectionSSLConnection	parse_urlLock)Retry)TokenInterface)ExponentialWithJitterBackoff	NoBackoff)EMPTY_RESPONSENEVER_DECODEAbstractRedis)
PIPELINE_BLOCKED_COMMANDSPRIMARYREPLICASLOT_IDAbstractRedisClusterLoadBalancerLoadBalancingStrategyblock_pipeline_commandget_node_nameparse_cluster_slots)READ_COMMANDSAsyncRedisClusterCommands)REDIS_CLUSTER_HASH_SLOTSkey_slot)CredentialProvider)#AfterAsyncClusterInstantiationEventEventDispatcher)AskErrorBusyLoadingErrorClusterDownErrorClusterErrorConnectionErrorCrossSlotTransactionError	DataErrorExecAbortErrorInvalidPipelineStackMaxConnectionsError
MovedErrorRedisClusterException
RedisErrorResponseErrorSlotNotCoveredErrorTimeoutErrorTryAgainError
WatchError)AnyKeyT
EncodableTKeyT)SSL_AVAILABLEdeprecated_argsdeprecated_functionget_lib_versionsafe_strstr_if_bytestruncate_text)
TLSVersionVerifyFlags
VerifyModeTargetNodesTClusterNodec            Z          \ rS rSrSr\S\S\SS 4S j5       rSr	\
" S/S	S
S9\
" S/SSS9SSSSSSSSSSSSSSSSSSS\" 5       SSSSSSSSSSSSSSSSSSSSSS4*S\\   S\\\4   S\\S      S \S\S!\\   S"\S#\S\S$\S%\S&   S'\\\\         S(\\\4   S)\\   S*\\   S+\\   S,\\   S-\\   S.\\   S/\\   S0\S1\S2\S3\S4\\   S5\S6\\\\\\4   4      S7\\   S8\S9\\   S:\\   S;\\\4   S<\\\      S=\\\      S>\\   S?\S@\\   SA\\   SB\\   SC\\   SD\\\\\4   /\\\4   4      SE\\   SS4VSF jj5       5       rSSG jrSSH jr \!" SISJSKSL9SSM j5       r"SSN jr#S\4SO jr$S\4SP jr%SQ r&S\'\SS 4   4SR jr(SSr)\*RV                  \,RZ                  4ST\SU\SS4SV jjr.SW\/SS4SX jr0S\S   4SY jr1S\S   4SZ jr2S\S   4S[ jr3SS\ jr4SS] jr5SS^ jr6   SS\\   S\\   S_\\   S\S   4S` jjr7 SSa\Sb\S\S   4Sc jjr8Sa\9S\4Sd jr:S\;4Se jr<S\=\\\   4   4Sf jr>S%\?SS4Sg jr@Sh\Si\ASS4Sj jrBSSk.Sh\Sl\Sm\\   S\S   4Sn jjrCSh\Sl\S\4So jrDSp\S\4Sq jrESp\S\S   4Sr jrFSl\9S\S\4Ss jrGStSSl\\H\94   S\S\4Su jrI SSv\\   Sw\\   SSx4Sy jjrJ       SSz\HS{\\   S|\S}\S~\\   S\\\K      S\S\S\K4S jjrLS\MSSx\4   4S jrNSrOg)RedisClusterd   a[  
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:
    | @deprecated - please use load_balancing_strategy instead
    | Enable read from replicas in READONLY mode.
      When set to true, read commands will be assigned between the primary and
      its replications in a Round-Robin manner.
      The data read from replicas is eventually consistent with the data in primary nodes.
:param load_balancing_strategy:
    | Enable read from replicas in READONLY mode and defines the load balancing
      strategy that will be used for cluster node selection.
      The data read from replicas is eventually consistent with the data in primary nodes.
:param dynamic_startup_nodes:
    | Set the RedisCluster's startup nodes to all the discovered nodes.
      If true (default value), the cluster's discovered nodes will be used to
      determine the cluster nodes-slots mapping in the next topology refresh.
      It will remove the initial passed startup nodes if their endpoints aren't
      listed in the CLUSTER SLOTS output.
      If you use dynamic DNS endpoints for startup nodes but CLUSTER SLOTS lists
      specific IP addresses, it is best to set it to false.
: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:
    | @deprecated - Please configure the 'retry' object instead
      In case 'retry' object is set - this argument is ignored!

      Number of times to retry before raising an error when :class:`~.TimeoutError`,
      :class:`~.ConnectionError`, :class:`~.SlotNotCoveredError`
      or :class:`~.ClusterDownError` are encountered
:param retry:
    | A retry object that defines the retry strategy and the number of
      retries for the cluster client.
      In current implementation for the cluster client (starting form redis-py version 6.0.0)
      the retry object is not yet fully utilized, instead it is used just to determine
      the number of retries for the cluster client.
      In the future releases the retry object will be used to handle the cluster client retries!
: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.
: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                     UR                  [        U5      5        UR                  SS5      [        L a  SUS'   U " S0 UD6$ )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ssl )updater   popr   )clsr\   r]   s      O/home/james-whalen/.local/lib/python3.13/site-packages/redis/asyncio/cluster.pyfrom_urlRedisCluster.from_url   s=    8 	in%::($/=@ F5M}V}    )_initialize_lockretrycommand_flagscommands_parserconnection_kwargsencoder
node_flagsnodes_managerread_from_replicasreinitialize_counterreinitialize_stepsresponse_callbacksresult_callbacksrs   z6Please configure the 'load_balancing_strategy' insteadz5.3.0)args_to_warnreasonversioncluster_error_retry_attemptsz+Please configure the 'retry' object insteadz6.0.0Ni  TF              r   zredis-pyzutf-8strictrequired   hostportstartup_nodesrX   require_full_coverageload_balancing_strategydynamic_startup_nodesru   max_connectionsrl   r    retry_on_error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_timeoutra   ssl_ca_certsssl_ca_datassl_cert_reqsssl_include_verify_flagsssl_exclude_verify_flagsssl_certfilessl_check_hostnamessl_keyfilessl_min_versionssl_ciphersprotocoladdress_remapevent_dispatcherc+                 ^   U(       a  [        S5      eU(       a  [        S5      eU(       a  U(       d  U(       d  [        S5      e0 SU
_S[        _SU_SU_SU_S	U_S
U_SU_SU_SU_SU_SU_SU_SU_SU_SU_SU(_n+U(       a!  U+R                  [        UUU U!U"U#U$U%U&U'S.5        U(       d  U(       a  U R                  U+S'   U(       a  Xl        O[        [        SSS9U	S9U l        U(       a  U R
                  R                  U5        [        R                  " 5       U+S'   U+R                  S5      S;   a  U+S   R                  [        5        OU+S   R                  [        5        U+U l        U(       aH  / n,U H=  n-U,R                  [!        U-R"                  U-R$                  40 U R                  D65        M?     U,nO/ nU(       a,  U(       a%  UR                  [!        X40 U R                  D65        U*c  ['        5       U l        OU*U l        X0l        [-        UUU+UU)U R(                  S9U l        [1        UUU5      U l        XPl        X`l        Xl        SU l        [=        5       U l        U R@                  RB                  R                  5       U l"        U R@                  RF                  R                  5       U l$        U+S   U l%        U R@                  RL                  R                  5       U l'        S U RN                  S '   S!U l(        S U l)        SU l*        [V        RX                  " 5       U l-        g )"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`   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   redis_connect_func   
   )basecap)backoffretriesrv   )3r}   )r   r   r   r   c                 N    [        [        UR                  5       5      S   40 UD6$ Nr   )r0   listvalues)cmdresr]   s      rf   <lambda>'RedisCluster.__init__.<locals>.<lambda>  s%    ':SZZ\"1%()/(ri   CLUSTER SLOTST).rC   r   rc   r   
on_connectrl   r    r"   update_supported_errorsr   r   getr   r   ro   appendrX   r   r   r7   _event_dispatcherr   NodesManagerrr   r   rp   rs   r   ru   rt   r   rn   	__class__
NODE_FLAGSrq   COMMAND_FLAGSrm   rv   RESULT_CALLBACKSrw   rj   rk   _usage_counterasyncior   _usage_lock).selfr   r   r   r   rs   r   r   ru   r{   r   rl   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   ra   r   r   r   r   r   r   r   r   r   r   r   r   r   r]   passed_nodesnodes.                                                 rf   __init__RedisCluster.__init__   s   | 'A  'E  D-'S "
"

"
 "#6	"

 "
 "
 ;"
 "
 ;"
 "
 "
  0"
 $%:"
  %&<!"
"  0#"
$ '(@%"
& n'"
( )"
. MM(5$0#.%20H0H$0*<#.'6#.  !8+/??F'(J4!D4DJ JJ..~>'6';';'=#$::j!X-'(//0DE'(//0DE!'L%##		499O8N8NO & )MMD  T!R4;Q;Q!RS#%4%6D"%5D"*)!"7'!33
 x:JK"4'>$"4$%!24..3388:!^^99>>@"()="> $ ? ? D D F 	o.  -1

  "<<>ri   c                   #    U R                   (       a  U R                  (       d  [        R                  " 5       U l        U R                   ISh  vN   U R                   (       aa   U R                  R                  5       I Sh  vN   U R                  R                  U R                  R                  5      I Sh  vN   SU l         SSS5      ISh  vN   U $ U $  N NX N#! [         aI    U R                  R                  5       I Sh  vN    U R                  R                  S5      I Sh  vN    e f = f Nd! , ISh  vN  (       d  f       U $ = f7f)zJGet all nodes from startup nodes & creates connections if not initialized.NFr   )
rj   rk   r   r   rr   
initializern   default_nodeBaseExceptionacloser   s    rf   r   RedisCluster.initialize  s     ::$\\^
zzz##	"00;;==="22== ..;;   ,1( "z t " > ) "0077999"0077HHH "zz s   AECED8&C C6C :C;C ED6	EC C  'D3D
#D3+D.,D33D86E8E>E?EEc                   #    U R                   (       d  U R                  (       d  [        R                  " 5       U l        U R                   ISh  vN   U R                   (       dL  SU l         U R                  R                  5       I Sh  vN   U R                  R                  S5      I Sh  vN   SSS5      ISh  vN   gg Ns N; N N! , ISh  vN  (       d  f       g= f7f)z.Close all connections & client if initialized.NTr   )rj   rk   r   r   rr   r   r   s    rf   r   RedisCluster.aclose  s     ::$\\^
zzz'''+D$,,33555,,33ODDD	 "zz   " 6D	 "zzzsl   AC%CC%6C	C
"C,C-C1C%<C	=C%CC	C%C"CC"C%z5.0.0zUse aclose() insteadclose)rz   ry   namec                 @   #    U R                  5       I Sh  vN   g N7f)z.alias for aclose() for backwards compatibilityN)r   r   s    rf   r   RedisCluster.close  s      kkm   c                    #    U R                  5       I Sh  vN    U R                  5       I Sh  vN $  N N! [         a    U R                  5       I Sh  vN    e f = f7f)z
Async context manager entry. Increments a usage counter so that the
connection pool is only closed (via aclose()) when no context is using
the client.
N)_increment_usager   	Exception_decrement_usager   s    rf   
__aenter__RedisCluster.__aenter__  s[      ##%%%	*** 	& + 	'')))	s:   A 4A 8 68 A 8 AAAA c                    #    U R                    ISh  vN   U =R                  S-  sl        U R                  sSSS5      ISh  vN   $  N6 N! , ISh  vN  (       d  f       g= f7f)zu
Helper coroutine to increment the usage counter while holding the lock.
Returns the new value of the usage counter.
Nr   r   r   r   s    rf   r   RedisCluster._increment_usage  A     
 ###1$&& $#####C   A(A
A(!AA(AA(A(A%AA%!A(c                    #    U R                    ISh  vN   U =R                  S-  sl        U R                  sSSS5      ISh  vN   $  N6 N! , ISh  vN  (       d  f       g= f7f)zu
Helper coroutine to decrement the usage counter while holding the lock.
Returns the new value of the usage counter.
Nr   r   r   s    rf   r   RedisCluster._decrement_usage  r   r   c                    #    [         R                  " U R                  5       5      I Sh  vN nUS:X  a-  [         R                  " U R                  5       5      I Sh  vN   gg N8 N7f)z
Async context manager exit. Decrements a usage counter. If this is the
last exit (counter becomes zero), the client closes its connection pool.
Nr   )r   shieldr   r   )r   exc_type	exc_value	tracebackcurrent_usages        rf   	__aexit__RedisCluster.__aexit__  sQ     
 &nnT-B-B-DEEA..///  F 0s!   (A'A#1A'A%A'%A'c                 >    U R                  5       R                  5       $ Nr   	__await__r   s    rf   r   RedisCluster.__await__       **,,ri   zUnclosed RedisCluster client_warn_grlc                     [        U S5      (       aT  U R                  (       dB  U" U R                   SU < 3[        U S9   X R                  S.nU" 5       R	                  U5        g g g ! [
         a     g f = f)Nrj    sourceclientmessage)hasattrrj   _DEL_MESSAGEResourceWarningcall_exception_handlerRuntimeError)r   r   r   contexts       rf   __del__RedisCluster.__del__  sw    
 4''0@0@T&&'q1?4P%)6G6GH--g6	 1A'
   s    $A' '
A43A4
connectionc                    #    UR                  5       I S h  vN   UR                  S5      I S h  vN   [        UR                  5       I S h  vN 5      S:w  a  [	        S5      eg  NN N7 N7f)NREADONLYOKzREADONLY command failed)r   send_commandrR   read_responser<   r   r  s     rf   r   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                 \    [        U R                  R                  R                  5       5      $ )zGet all nodes of the cluster.)r   rr   nodes_cacher   r   s    rf   	get_nodesRedisCluster.get_nodes*  s"    D&&2299;<<ri   c                 @    U R                   R                  [        5      $ )z%Get the primary nodes of the cluster.)rr   get_nodes_by_server_typer(   r   s    rf   get_primariesRedisCluster.get_primaries.      !!::7CCri   c                 @    U R                   R                  [        5      $ )z%Get the replica nodes of the cluster.)rr   r  r)   r   s    rf   get_replicasRedisCluster.get_replicas2  r  ri   c                     [         R                  " [        U R                  R                  R                  5       5      5      $ )z!Get a random node of the cluster.)randomchoicer   rr   r  r   r   s    rf   get_random_nodeRedisCluster.get_random_node6  s+    }}T$"4"4"@"@"G"G"IJKKri   c                 .    U R                   R                  $ )z#Get the default node of the client.)rr   r   r   s    rf   get_default_nodeRedisCluster.get_default_node:  s    !!...ri   c                     U(       a  U R                  UR                  S9(       d  [        S5      eXR                  l        g)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   r>   rr   r   )r   r   s     rf   set_default_nodeRedisCluster.set_default_node>  s0     4==499==OPP*.'ri   r#  c                 :    U R                   R                  XU5      $ )z&Get node by (host, port) or node_name.)rr   r$  r   r   r   r#  s       rf   r$  RedisCluster.get_nodeI  s     !!**4yAAri   keyreplicac                    U R                  U5      nU R                  R                  R                  U5      nU(       d  [	        SU S35      eU(       a-  [        U R                  R                  U   5      S:  a  gSnXE   $ SnXE   $ )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.r   Nr   r   )keyslotrr   slots_cacher   rF   len)r   r*  r+  slot
slot_cachenode_idxs         rf   get_node_from_keyRedisCluster.get_node_from_keyR  s     ||C ''3377=
%tf4T&UVV4%%11$781<H ## H##ri   c                 J    [        U R                  R                  U5      5      $ )zk
Find the keyslot for a given key.

See: https://redis.io/docs/manual/scaling/#redis-cluster-data-sharding
)r4   rp   encode)r   r*  s     rf   r.  RedisCluster.keyslotn  s     ++C011ri   c                     U R                   $ )z%Get the encoder object of the client.)rp   r   s    rf   get_encoderRedisCluster.get_encoderv  s    ||ri   c                     U R                   $ )zGGet the kwargs passed to :class:`~redis.asyncio.connection.Connection`.)ro   r   s    rf   get_connection_kwargs"RedisCluster.get_connection_kwargsz  s    %%%ri   c                     Xl         g r   )rl   )r   rl   s     rf   	set_retryRedisCluster.set_retry~  s    
ri   commandcallbackc                      X R                   U'   g)zSet a custom response callback.N)rv   )r   rB  rC  s      rf   set_response_callback"RedisCluster.set_response_callback  s    +3(ri   )	node_flagargsrG  c                  #    U(       d  U R                   R                  U5      nX R                  ;   GaA  X R                  R                  :X  a  U R
                  R                  /$ X R                  R                  :X  a  U R
                  R                  [        5      $ X R                  R                  :X  a  U R
                  R                  [        5      $ X R                  R                  :X  a-  [        U R
                  R                  R                  5       5      $ X R                  R                   :X  aB  ["        R$                  " [        U R
                  R                  R                  5       5      5      /$ U R
                  R'                  U R(                  " U/UQ76 I S h  vN U R*                  =(       a	    U[,        ;   U[,        ;   a  U R.                  5      /$ S 5      /$  N@7fr   )rm   r   rq   r   DEFAULT_NODErr   r   	PRIMARIESr  r(   REPLICASr)   	ALL_NODESr   r  r   RANDOMr  r  get_node_from_slot_determine_slotrs   r1   r   )r   rB  rG  rH  s       rf   _determine_nodesRedisCluster._determine_nodes  s{    
 **..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::''DG},D07=0H,,
 	
 OS
 	
:s   FG$!G""AG$c                   #    U R                   R                  U5      [        :X  a  [        US   5      $ UR	                  5       S;   aX  [        U5      S:  a  [        SU/UQ7 35      eUSS[        US   5      -    nU(       d  [        R                  " S[        5      $ OiU R                  R                  " U/UQ76 I S h  vN nU(       d=  UR	                  5       S;   a  [        R                  " S[        5      $ [        SU 35      e[        U5      S:X  a  U R                  US   5      $ U Vs1 s H  o@R                  U5      iM     nn[        U5      S:w  a  [        U S35      eUR                  5       $  Ns  snf 7f)	Nr   )EVALEVALSHAr   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)rm   r   r*   intupperr0  rC   r  	randranger3   rn   get_keysr.  rd   )r   rB  rH  keysr*  slotss         rf   rP  RedisCluster._determine_slot  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%   B>F  E9A/F 0E;
0F ;F target_nodesc                 L    [        U[        5      =(       a    XR                  ;   $ r   )
isinstancestrrq   )r   r_  s     rf   _is_node_flagRedisCluster._is_node_flag  s    ,,P1PPri   c                     [        U[        5      (       a  UnU$ [        U[        5      (       a  U/nU$ [        U[        5      (       a  [        UR	                  5       5      nU$ [        S[        U5       35      e)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 )ra  r   rX   dictr   	TypeErrortype)r   r_  nodess      rf   _parse_target_nodes RedisCluster._parse_target_nodes  s    lD)) E   k22!NE  d++ ,,./E  & '+<&8%9; ri   c           
        ^ ^^#    TS   n/ nSnT R                   R                  5       nTR                  SS5      nU(       a+  T R                  U5      (       d  T R	                  U5      nSnSnSU-   n[        U5       GH  n	T R                  (       aN  T R                  5       I Sh  vN   [        U5      S:X  a'  US   T R                  5       :X  a  T R                  5          U(       d0  T R                  " TSU06I Sh  vN nU(       d  [        ST S	35      e[        U5      S:X  a\  T R                  " US   /TQ70 TD6I Sh  vN n
UT R                  ;   a'  T R                  U   " X4S   R                  U
040 TD6s  $ U
s  $ U Vs/ s H  oR                  PM     nn[         R"                  " UUU 4S
 jU 5       6 I Sh  vN nUT R                  ;   a+  T R                  U   " U[%        ['        X5      5      40 TD6s  $ [%        ['        X5      5      s  $    g GNt GN Ns  snf  Ne! [(         a<  nUS:  a/  [+        U5      T R,                  R.                  ;   a  US-  n SnAGM  UeSnAff = f7f)a!  
Execute a raw command on the appropriate cluster node or target_nodes.

It will retry the command as specified by the retries property of
the :attr:`retry` & 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   rG  !No targets were found to execute  command onc              3   x   >#    U  H/  n[         R                  " TR                  " U/TQ70 TD65      v   M1     g 7fr   )r   create_task_execute_command).0r   rH  r]   r   s     rf   	<genexpr>/RedisCluster.execute_command.<locals>.<genexpr>0  sD       )5 $// $ 5 5d LT LV L  )5s   7:)rl   get_retriesrd   rc  rj  rangerj   r   r0  r  replace_default_noderQ  rC   rq  rw   r   r   gatherrf  zipr   rh  r   ERRORS_ALLOW_RETRY)r   rH  r]   rB  r_  target_nodes_specifiedretry_attemptspassed_targetsexecute_attempts_retr   r\  r   es   ```            rf   execute_commandRedisCluster.execute_command  sw    $ q'!&//1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   B I1%H&:I1!H(=H>AH(H8H(<I1?H( I1H(H!$H( H&<H(=I1 H(I1H(H(!H((
I.2.I) I1'I))I..I1target_nodec                 Z  #    S=pES nU R                   nUS:  a  US-  n U(       a+  U R                  US9nUR                  S5      I S h  vN   SnOsU(       al  U R                  " U6 I S h  vN nU R                  R                  UU R                  =(       a    US   [        ;   US   [        ;   a  U R                  OS 5      nSnUR                  " U0 UD6I S h  vN $ [=        S5      e N N N! [         a    e [         a    e [        [        4 aK    U R                  R                  R                  UR                  S 5        U R!                  5       I S h  vN    e ["        [$        4 a:    U R!                  5       I S h  vN    [&        R(                  " S5      I S h  vN    e [*         a  n	U =R,                  S-  sl        U R.                  (       a>  U R,                  U R.                  -  S:X  a!  U R!                  5       I S h  vN    SU l        OXR                  l        Sn S n	A	OvS n	A	f[2         a*  n	[5        U	R6                  U	R8                  S9nSn S n	A	ODS n	A	f[:         a4    XpR                   S	-  :  a  [&        R(                  " S
5      I S h  vN     Of = fUS:  a  GM  GN7f)NFr   r   r"  ASKING      ?Tr   r   r   g?zTTL exhausted.)RedisClusterRequestTTLr$  r  rP  rr   rO  rs   r1   r   r9   rA   r<   rG   r   rd   r   r   r:   rF   r   sleeprB   rt   ru   _moved_exceptionr8   r/   r   r   rH   r;   )
r   r  rH  r]   askingmovedredirect_addrttlr1  r  s
             rf   rq  RedisCluster._execute_commandF  s\     ))Ag1HCK."&----"HK%55h???"F "&!5!5t!<<D"&"4"4"G"G//LDG}4L7m3 44!#K "E(88$I&IIIv +,,U @
 = J# & 
 #\2 	
 ""0044[5E5EtL kkm##$&9:  kkm##mmD)))  ))Q.)++11D4K4KKqP++-''01D-:;&&7  -166 G  .44q88!-----.W Aggs   J+*C0 
C* C0 +C,,A.C0 C.C0 J+*C0 ,C0 .C0 0A'JE(J FJF" J/AH*HH*%J+*J7 IJ+8JJJJ+J	J+transaction
shard_hintClusterPipelinec                 <    U(       a  [        S5      e[        X5      $ )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 mode)rC   r  )r   r  r  s      rf   pipelineRedisCluster.pipeline  s     '(RSSt11ri   r   timeoutr  blockingblocking_timeout
lock_classthread_localraise_on_release_errorc	                 .    Uc  [         nU" U UUUUUUUS9$ )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.

``raise_on_release_error`` indicates whether to raise an exception when
the lock is no longer owned when exiting the context manager. By default,
this is True, meaning an exception will be raised. If False, the warning
will be logged and the exception will be suppressed.

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  r  r  r  r  r  r   )	r   r   r  r  r  r  r  r  r  s	            rf   lockRedisCluster.lock  s5    H J-%#9	
 		
ri   funcc                   #    UR                  SS5      nUR                  SS5      nUR                  SS5      nU R                  SU5       ISh  vN n  U(       a  UR                  " U6 I Sh  vN   U" U5      I Sh  vN nUR                  5       I Sh  vN n	U(       a  UOU	 sSSS5      ISh  vN   $  Ni NK N= N' N! [         a#    Ub  US:  a  [
        R                  " U5         M  f = f! , ISh  vN  (       d  f       g= f7f)z
Convenience method for executing the callable `func` as a transaction
while watching all keys specified in `watches`. The 'func' callable
should expect a single argument which is a Pipeline object.
r  Nvalue_from_callableFwatch_delayTr   )rd   r  watchexecuterI   timer  )
r   r  watchesr]   r  r  r  pipe
func_value
exec_values
             rf   r  RedisCluster.transaction  s      ZZd3
$jj)>Fjj5==z22d	"jj'222'+Dz!1J'+||~!5J)<:*L 322 3!1!5 3 " ".;?

;/ 322s   ADB9DC3C/B;0C?B= CB?C'D3C4D;C=C?CD)C0,C3/C00C33D
9C<:D
D)r   rj   rk   r   r   rm   rn   ro   rp   r   rq   rr   rs   rt   ru   rv   rw   rl   r   )r^   rZ   r^   N)r^   rX   )r   rX   r^   NNNNF)NN)Ng?TNNTT)P__name__
__module____qualname____firstlineno____doc__classmethodrb  r   rg   	__slots__rN   rP   r   r   rX  r   boolr-   r   r   r5   floatr   bytesrV   rU   rT   r   r   r7   r   r   r   rO   r   r   r   r   r   r   r   r   warningswarnr   get_running_loopr  r   r   r  r  r  r  r  r%  r$  r4  rK   r.  r   r:  r   r=  r    r@  r   rE  rQ  rP  rc  rj  r  rL   rq  r  r   r  r	   r  __static_attributes__rb   ri   rf   rZ   rZ   d   sP   cJ 3 # .  @I" *+G
 *
 = # $7;&*#(CG&*"#,-$#':>"<@"&"&%)",%4%6'!&'(26!&NR*.&*%)0:@D@D&*#'%)04%)"#PT6:at*smt* CHot*
  ] 34t*  $t* !t* "**?!@t*  $t*  t* '*t* t*  t* !d9o!67t*  #s(O!t*" sm#t*$ &&89%t*& 3-'t*( 3-)t** c]+t*, 3--t*. c]/t*2 3t*4 5t*6 7t*:  %;t*< !)=t*> ?t*@ #+73c5j8I3I+J"KAt*B !Ct*F Gt*H smIt*J c]Kt*L S*_-Mt*N #+4+<"=Ot*P #+4+<"=Qt*R smSt*T !Ut*V c]Wt*X "*-Yt*Z c][t*\ 3-]t*^  %S/):E#s(O)K LM_t*` #?3at*b 
ct*t*l&	E 1GgV W' '' '0-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#,>'? &u  4S 4<M 4RV 4
 DH!
!
#&!
3;C=!
	m	!
F1S 1 1 1fQ# Q$ Q ]8K (R: R R RhV-(V-16tZ7G1HV-TWV-	V-r NR2#C=2=Ec]2	2$ $(,0+/!'+O
O
 %O
 	O

 O
 #5/O
 T$Z(O
 O
 !%O
 
O
bd$5s:;ri   rZ   c                   `   \ rS rSrSrSr S'S\S.S\S\\\	4   S	\
\   S
\	S\\   S\SS4S jjjrS\4S jrS\S\4S jrSr\R&                  \R*                  4S\S\SS4S jjrS(S jrS\4S jrS\SS4S jrS\S\S\S\4S jrS\S\S\4S jrS\S    S\4S! jrS"\4S# jrS$\ 4S% jr!S&r"g))rX   i  z
Create a new ClusterNode.

Each ClusterNode manages multiple :class:`~redis.asyncio.connection.Connection`
objects for the (host, port).
)_connections_freerk   r   r`   ro   r   r   r   r   rv   server_typeNr~   )r   r`   r   r   r  r   r`   ro   r^   c                   US:X  a  [         R                  " U5      nXS'   X&S'   Xl        X l        [	        X5      U l        X0l        X@l        XPl        X`l	        UR                  S0 5      U l        / U l        [        R                  " U R                  S9U l        U R                  R!                  SS 5      U l        U R"                  c  [%        5       U l        g g )N	localhostr   r   rv   )maxlenr   )socketgethostbynamer   r   r/   r   r  r   r`   ro   rd   rv   r  collectionsdequer  r   r   r7   )r   r   r   r  r   r`   ro   s          rf   r   ClusterNode.__init__.  s     ;''-D$(&!$(&!		!$-	&. 0!2"3"7"78Lb"Q.0(3(9(9AUAU(V
!%!7!7!;!;<NPT!U!!)%4%6D" *ri   c           	      p    SU R                    SU R                   SU R                   SU R                   S3	$ )Nz[host=z, port=z, name=z, server_type=])r   r   r   r  r   s    rf   __repr__ClusterNode.__repr__M  s?    TYYKwtyyk 2II;nT-=-=,>aA	
ri   objc                 b    [        U[        5      =(       a    UR                  U R                  :H  $ r   )ra  rX   r   )r   r  s     rf   __eq__ClusterNode.__eq__S  s!    #{+EDII0EEri   zUnclosed ClusterNode objectr   r   c                     U R                    HW  nUR                  (       d  M  U" U R                   SU < 3[        U S9   X R                  S.nU" 5       R	                  U5          g    g ! [
         a     Nf = f)Nr   r   r   )r  is_connectedr   r   r   r  )r   r   r   r  r  s        rf   r  ClusterNode.__del__X  sz    
 ++J&&&**+1TH5tT)-:K:KLGF11':  , $ s    $A))
A65A6c                    #    [         R                  " S U R                   5       SS06I S h  vN n[        S U 5       S 5      nU(       a  Ueg  N!7f)Nc              3   j   #    U  H)  n[         R                  " UR                  5       5      v   M+     g 7fr   r   rp  
disconnect)rr  r  s     rf   rs  )ClusterNode.disconnect.<locals>.<genexpr>j  s.      "3J ##J$9$9$;<<"3   13return_exceptionsTc              3   T   #    U  H  n[        U[        5      (       d  M  Uv   M      g 7fr   )ra  r   )rr  r   s     rf   rs  r  p  s     E3C*S)*DCC3s   (	()r   rx  r  next)r   r  excs      rf   r  ClusterNode.disconnecth  s[     NN"&"3"3

 #
 
 E3EtLI 
s   +AA"Ac                 |    U R                   R                  5       $ ! [         a    [        U R                  5      U R
                  :  ag  [        [        5       S[        4S9nU R                  R                  5       nXS'   U R                  " S0 UD6nU R                  R                  U5        Us $ [        5       ef = f)Nr   )r   r   supported_errorsrl   rb   )r  popleft
IndexErrorr0  r  r   r    r#   r<   ro   r   r`   r   rA   )r   rl   ro   r  s       rf   acquire_connectionClusterNode.acquire_connectiont  s    	(::%%'' 	(4$$%(<(<< %K&5%7
 %)$:$:$?$?$A!-2'*!22G5FG
!!((4!!%''-	(s    BB;0B;r  c                 :    U R                   R                  U5        g)z(
Release connection back to free queue.
N)r  r   r  s     rf   releaseClusterNode.release  s     	

*%ri   rB  r]   c                   #     [         U;   a-  UR                  SS9I S h  vN nUR                  [         5        OUR                  5       I S h  vN n [        U;   a  UR                  [        5        UR                  SS 5        X R
                  ;   a  U R
                  U   " U40 UD6$ U$  N N_! [         a    [        U;   a  U[           s $ e f = f7f)NT)disable_decodingr\  )r%   r
  rd   rE   r$   rv   )r   r  rB  r]   responses        rf   parse_responseClusterNode.parse_response  s     		v%!+!9!94!9!PP

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

64  ---**73HGGG' Q < 	'n--	sU   CB0 B,B0 CB0 B.B0 AC,B0 .B0 0CCCCrH  c                 4  #    U R                  5       nUR                  UR                  " U6 S5      I S h  vN    U R                  " X1S   40 UD6I S h  vN U R                  R                  U5        $  N> N!! U R                  R                  U5        f = f7f)NFr   )r  send_packed_commandpack_commandr  r  r   )r   rH  r]   r  s       rf   r  ClusterNode.execute_command  s     ,,.
 ,,Z-D-Dd-KUSSS	*,,ZaKFKK JJj) 	T L JJj)s8   3BA4BA8 A6A8 B6A8 8BBcommandsPipelineCommandc                   #    U R                  5       nUR                  UR                  S U 5       5      S5      I S h  vN   SnU H;  n U R                  " X$R                  S   40 UR
                  D6I S h  vN Ul        M=     U R                  R                  U5        U$  Nd N,! [         a  nXTl        Sn S nAMx  S nAff = f7f)Nc              3   8   #    U  H  oR                   v   M     g 7fr   )rH  )rr  r   s     rf   rs  /ClusterNode.execute_pipeline.<locals>.<genexpr>  s     $B#XXs   Fr   T)
r  r  pack_commandsr  rH  r]   resultr   r  r   )r   r  r  r  r   r  s         rf   execute_pipelineClusterNode.execute_pipeline  s     ,,.
 ,,$$$B$BBE
 	
 	

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

*%
%	
  
sK   <CB#C-B'8B%9	B'"C%B''
C1B?9C?CCtokenc                   ^ ^^#    [         R                  " 5       nT R                  (       a  T R                  R                  5       mTR                  R                  UU4S jU 4S j5      I S h  vN   TR                  R                  U4S jU 4S j5      I S h  vN   UR                  T5        T R                  (       a  M  U(       a5  UR                  5       mT R                  R                  T5        U(       a  M4  g g  N Ng7f)Nc                  d   > T R                  STR                  S5      TR                  5       5      $ )NAUTHoid)r	  try_get	get_value)connr  s   rf   r   .ClusterNode.re_auth_callback.<locals>.<lambda>  s'    ))EMM%0%//2Cri   c                 &   > TR                  U 5      $ r   _mockerrorr   s    rf   r   r    s    djj/ri   c                  $   > T R                  5       $ r   )r
  )r  s   rf   r   r    s    **,ri   c                 &   > TR                  U 5      $ r   r  r  s    rf   r   r    s    DJJu<Mri   )r  r  r  r  rl   call_with_retryr   )r   r  	tmp_queuer  s   `` @rf   re_auth_callbackClusterNode.re_auth_callback  s     %%'	jj::%%'D**,, 0	   **,,,.M   T" jjj $$&DJJd# is0   A)D.D /+DD&D9D>DDr  c                    #    g7f)z_
Dummy functions, needs to be passed as error callback to retry object.
:param error:
:return:
Nrb   r   r  s     rf   r  ClusterNode._mock  s
      	   )r  r   r  r`   ro   r   r   r   r   rv   r  r   r  )#r  r  r  r  r  r  r   rb  r   rX  r   r   r   r   r  r  r  r   r  r  r   r  r  r  r  r  r  r  r   r  r!   r  rD   r  r  rb   ri   rf   rX   rX     sj   I& &*	7  %-777 CHo7 c]	7 7 z*7 !7 
7>
# 
F# F$ F 1L ]],,  
	 
(J (6&* & &$/2>A	4*3 *# *# *t4E/F 4 2$N $& ri   c                   z   \ rS rSrSr   S!S\S   S\S\\\	4   S\S	\
\\\\4   /\\\4   4      S
\
\   SS4S jjr   S"S\
\   S\
\   S\
\   S\
S   4S jjr S#S\\S4   S\\S4   S\SS4S jjrS rS$S jr  S%S\S\SS4S jjrS\S\S   4S jrS$S jrS&S\SS4S jjrS\S\S\\\4   4S jrS rg)'r   i  )_dynamic_startup_nodesr  r   ro   r   r  read_load_balancerr   r/  r   r   Nr   rX   r   ro   r   r   r   r^   c                 
   U Vs0 s H  owR                   U_M     snU l        X l        X0l        XPl        S U l        0 U l        0 U l        [        5       U l	        X@l
        S U l        Uc  [        5       U l        g X`l        g s  snf r   )r   r   r   ro   r   r   r  r/  r,   r  r  r  r7   r   )r   r   r   ro   r   r   r   r   s           rf   r   NodesManager.__init__  s     ;HH-$iio-H%:"!2*+/57;="..,A#,0#%4%6D"%5" Is   B r   r   r#  c                     U(       aE  U(       a>  US:X  a  [         R                  " U5      nU R                  R                  [	        XS95      $ U(       a  U R                  R                  U5      $ [        S5      e)Nr  r  zEget_node requires one of the following: 1. node name 2. host and port)r  r  r  r   r/   r>   r(  s       rf   r$  NodesManager.get_node  sg     D{"++D1##''4(KLL##''	22W ri   oldnew
remove_oldc                 h   U(       aZ  [        UR                  5       5       H=  nXB;  d  M
  [        R                  " UR	                  U5      R                  5       5      nM?     UR                  5        H=  u  pFXA;   a/  X   UL a  M  [        R                  " X   R                  5       5      nXaU'   M?     g r   )r   r\  r   rp  rd   r  items)r   r  r  r  r   taskr   s          rf   	set_nodesNodesManager.set_nodes-  s     SXXZ(?"..swwt}/G/G/IJD ) ))+JD{9$**39+?+?+ABI &ri   c                     Xl         g r   )r  )r   	exceptions     rf   update_moved_exception#NodesManager.update_moved_exception?  s     )ri   c                 .   U R                   nU R                  UR                  UR                  S9nU(       a   UR                  [
        :w  a  [
        Ul        OX[        UR                  UR                  [
        40 U R                  D6nU R                  U R                  UR                  U05        X R                  UR                     ;   a  U R                  UR                     S   n[        Ul        U R                  UR                     R                  U5        U R                  UR                     R                  U5        X R                  UR                     S'   U R                   U:X  a  X l        OU/U R                  UR                  '   S U l         g )Nr  r   )r  r$  r   r   r  r(   rX   ro   r  r  r   r/  slot_idr)   r   remover   )r   r  redirected_nodeold_primarys       rf   _update_moved_slots NodesManager._update_moved_slotsB  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' $ri   r1  rs   c                    U R                   (       a  U R                  5         USL a  Uc  [        R                  n [	        U R
                  U   5      S:  ah  U(       aa  U R
                  U   S   R                  nU R                  R                  U[	        U R
                  U   5      U5      nU R
                  U   U   $ U R
                  U   S   $ ! [        [        4 a    [        SU SU R                   S35      ef = f)NTr   r   r-  z5" not covered by the cluster. "require_full_coverage=")r  r*  r-   ROUND_ROBINr0  r/  r   r  get_server_indexr  rg  rF   r   )r   r1  rs   r   primary_namer3  s         rf   rO  NodesManager.get_node_from_sloth  s      $$&%*A*I&;&G&G#	4##D)*Q.3J#//5a8==22CC #d&6&6t&<"=?V ''-h77##D)!,,I& 	% **.*D*D)EQH 	s   BC ?C -C>r  c                     U R                   R                  5        Vs/ s H  nUR                  U:X  d  M  UPM     sn$ s  snf r   )r  r   r  )r   r  r   s      rf   r  %NodesManager.get_nodes_by_server_type  sF     ((//1
1;. 1
 	
 
s   >>c           
        #    U R                   R                  5         0 n0 n/ nSnSnS n[        U R                  R	                  5       5       GH  n  U R
                  R                  [        U R                  U R                  R                  SS 5      5      5        UR                  S5      I S h  vN nSn[        U5      S:X  a>  US   S   S   (       d.  [        U R                  5      S:X  a  UR                   US   S   S'   U GH  n
[#        S[        U
5      5       H#  nX    Vs/ s H  n[%        U5      PM     snX'   M%     U
S   nUS   nUS	:X  a  UR                   n['        US   5      nU R)                  X5      u  p/ nUR                  [+        X5      5      nU(       d  [-        X[.        40 U R                  D6nUUUR0                  '   UR3                  U5        U
S
S  nU H|  nUS   nUS   nU R)                  X5      u  pUR                  [+        X5      5      nU(       d  [-        X[4        40 U R                  D6nUUUR0                  '   UR3                  U5        M~     [#        ['        U
S   5      ['        U
S   5      S-   5       H  nX;  a  UX+'   M  X+   S   nUR0                  UR0                  :w  d  M1  UR3                  UR0                   SUR0                   SU 35        [        U5      S:  d  Mo  [        SSR7                  U5       35      e   GM     Sn[#        [8        5       H  nX;  d  M
  Sn  O   U(       d  GM     O   U(       d  [        S[;        U5       35      UeU(       d0  U R<                  (       a  [        S[        U5       S[8         S35      eX l        U RA                  U R                  USS9  U RB                  (       a%  U RA                  U R                  U R                  SS9  U RE                  [.        5      S   U l#        S U l$        g  GNs! [         a    [        S5      ef = f! [         a  n	U	n S n	A	GM  S n	A	ff = fs  snf 7f)NFr   r   z(Cluster mode is not enabled on this nodeTr   r   r    r}   z vs z
 on slot: r|   z6startup_nodes could not agree on a valid slots cache: z, zORedis Cluster cannot be connected. Please provide at least one reachable node: z9All slots are not covered after query all startup_nodes. z of z covered...)r  )%r  resettupler   r   r   dispatchr6   r  ro   r   r  rE   rC   r   r0  r   rv  rR   rX  remap_host_portr/   rX   r(   r   r   r)   joinr3   rb  r   r/  r  r  r  r   r  )r   tmp_nodes_cache	tmp_slotsdisagreementsstartup_nodes_reachablefully_coveredr"  startup_nodecluster_slotsr  r1  ivalprimary_noder   r   nodes_for_slotr  replica_nodesreplica_nodetarget_replica_nodetmp_slots                         rf   r   NodesManager.initialize  sx    %%'4646	"'	 "$"4"4";";"=>L**33; ,, 22667LdS +7*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 $QR$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 }C ?F ''''*9~&68  !;!; (Ky>"$'?&@ A  %t''TJ&&NN4--t/?/?DNQ !99'B1E $i %X$ /B 
   		, Es|   AQAP%/P"0P%4P>6A1Q'Q
<E?Q?:Q=;Q<QCQ"P%%P;;P>>
QQ
QQQattrc                    #    S U l         [        R                  " S [        X5      R	                  5        5       6 I S h  vN   g  N7f)Nc              3   j   #    U  H)  n[         R                  " UR                  5       5      v   M+     g 7fr   r  rr  r   s     rf   rs  &NodesManager.aclose.<locals>.<genexpr>  s,      8D ##DOO$5668r  )r   r   rx  getattrr   )r   rK  s     rf   r   NodesManager.aclose  s>      nn#D/668
 	
 	
s   <AAAc                 N    U R                   (       a  U R                  X45      $ X4$ )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   r   s      rf   r9  NodesManager.remap_host_port  s(     %%tl33zri   )r  r   r  r   ro   r   r  r  r   r/  r   )TNNr  r  r  )FN)r  )r  r  r  r  r  r   r  r   rb  r   r   r   r   rX  r7   r   r$  r  r#  r*  rO  r  r   r   r9  r  rb   ri   rf   r   r     s   I& '+PT6:6M*6  $6  S>	6
  $6  %S/):E#s(O)K LM6 #?36 
68 #"#'	sm sm C=	
 
-	 , !	#}$% #}$% 	
 
$*$%R $) $	 !
 
6
C 
D<O 
H%T
 
 
C s uS#X ri   r   c                   *   \ rS rSrSrSr S!S\S\\   SS4S jjr	S"S	 jr
S"S
 jrS#S jrS\\SS 4   4S jrS\4S jrS\4S jrS\\\4   S\SS 4S jr S$S\S\S\\   4S jjrS\S\SS 4S jrS rS rS rS rS rS r S\!\"\4   SS 4S jr#S r$g)%r  i(  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
)cluster_client_transaction_execution_strategyNr   r  r^   c                     Xl         X l        U R                  (       d  [        U 5      U l        g [        U 5      U l        g r   )rU  rV  PipelineStrategyTransactionStrategyrW  )r   r   r  s      rf   r   ClusterPipeline.__init__O  s?     %' $$ T" 	  %T* 	 ri   c                 V   #    U R                   R                  5       I S h  vN   U $  N7fr   )rW  r   r   s    rf   r   ClusterPipeline.initializeZ  s'     &&11333 	4s   )')c                 >   #    U R                  5       I S h  vN $  N7fr   )r   r   s    rf   r   ClusterPipeline.__aenter__^  s     __&&&&s   c                 @   #    U R                  5       I S h  vN   g  N7fr   r6  )r   r   r   r   s       rf   r   ClusterPipeline.__aexit__a       jjlr   c                 >    U R                  5       R                  5       $ r   r   r   s    rf   r   ClusterPipeline.__await__d  r   ri   c                     g)z?Pipeline instances should  always evaluate to True on Python 3+Trb   r   s    rf   __bool__ClusterPipeline.__bool__g  s    ri   c                 ,    [        U R                  5      $ r   )r0  rW  r   s    rf   __len__ClusterPipeline.__len__k  s    4++,,ri   rH  r]   c                 :    U R                   R                  " U0 UD6$ )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
)rW  r  r   rH  r]   s      rf   r  ClusterPipeline.execute_commandn  s      ''77HHHri   raise_on_errorallow_redirectionsc                    #     U R                   R                  X5      I Sh  vN U R                  5       I Sh  vN   $  N N! U R                  5       I Sh  vN    f = f7f)a  
Execute the pipeline.

It will retry the commands as specified by retries specified in :attr:`retry`
& 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)rW  r  r6  r   ro  rp  s      rf   r  ClusterPipeline.execute~  sP     $	1199  **,	 $**,sE   A!A ?A A!AA!A A!AAAA!rB  r\  c                     U R                   R                  U5      R                  5        H  nU R                  " U/UQ76   M     U $ r   )rU  _partition_keys_by_slotr   r  )r   rB  r\  	slot_keyss       rf   _split_command_across_slots+ClusterPipeline._split_command_across_slots  sC     ,,DDTJQQSI  595 T ri   c                 T   #    U R                   R                  5       I Sh  vN   g N7fz
Reset back to empty pipeline.
N)rW  r6  r   s    rf   r6  ClusterPipeline.reset  s      &&,,...   (&(c                 8    U R                   R                  5         g)zz
Start a transactional block of the pipeline after WATCH commands
are issued. End the transactional block with `execute`.
N)rW  multir   s    rf   r~  ClusterPipeline.multi  s    
 	  &&(ri   c                 T   #    U R                   R                  5       I Sh  vN   g N7f)r5  N)rW  discardr   s    rf   r  ClusterPipeline.discard       &&..000r|  c                 R   #    U R                   R                  " U6 I Sh  vN   g N7f)z$Watches the values at keys ``names``N)rW  r  r   namess     rf   r  ClusterPipeline.watch  s     &&,,e444   '%'c                 T   #    U R                   R                  5       I Sh  vN   g N7f)z'Unwatches all previously specified keysN)rW  unwatchr   s    rf   r  ClusterPipeline.unwatch  r  r|  c                 R   #    U R                   R                  " U6 I S h  vN   g  N7fr   )rW  unlinkr  s     rf   r  ClusterPipeline.unlink  s     &&--u555r  mappingc                 8    U R                   R                  U5      $ r   )rW  mset_nonatomicr   r  s     rf   r  ClusterPipeline.mset_nonatomic  s     ''66w??ri   )rW  rV  rU  r   r^   r  )r   Nr   Nr   Nr^   NTT)%r  r  r  r  r  r  rZ   r   r  r   r   r   r   r   r   r   rg  rX  rj  r   rL   rK   r  r   r  rb  rw  r6  r~  r  r  r  r  r   rJ   r  r  rb   ri   rf   r  r  (  s(   "H JI CG	
"	
19$	
		
'-9S$0A%AB -$ - -I4+,I8;I	I" GK"?C	c2#'	/)1516@w
23@	@ri   r  r   r  r  c                   <    \ rS rSrS\S\S\SS4S jrS\4S jrS	r	g)
r  i  positionrH  r]   r^   Nc                 6    X l         X0l        Xl        S U l        g r   rH  r]   r  r  )r   r  rH  r]   s       rf   r   PipelineCommand.__init__  s    	 -1ri   c                 V    SU R                    SU R                   SU R                   S3$ )N[z]  ())r  rH  r]   r   s    rf   r  PipelineCommand.__repr__  s)    4==/DII;bQ??ri   r  )
r  r  r  r  rX  r   r   rb  r  r  rb   ri   rf   r  r    s1    2 2S 2C 2D 2@# @ri   r  c            	          \ rS rSr\SS j5       r\S\\\4   S\	SS4S j5       r
\ SS\S	\S\\	   4S
 jj5       r\S\\\4   SS4S j5       r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       r\S\4S j5       rSrg)ExecutionStrategyi  r^   r  c                    #    g7f)zF
Initialize the execution strategy.

See ClusterPipeline.initialize()
Nrb   r   s    rf   r   ExecutionStrategy.initialize  
      	r  rH  r]   c                     g)zN
Append a raw command to the pipeline.

See ClusterPipeline.execute_command()
Nrb   rm  s      rf   r  !ExecutionStrategy.execute_command       	ri   ro  rp  c                    #    g7f)z
Execute the pipeline.

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

See ClusterPipeline.execute()
Nrb   rr  s      rf   r  ExecutionStrategy.execute  s
      	r  r  c                     g)zu
Executes multiple MSET commands according to the provided slot/pairs mapping.

See ClusterPipeline.mset_nonatomic()
Nrb   r  s     rf   r   ExecutionStrategy.mset_nonatomic  r  ri   c                    #    g7f)zB
Resets current execution strategy.

See: ClusterPipeline.reset()
Nrb   r   s    rf   r6  ExecutionStrategy.reset  r  r  c                     g)z=
Starts transactional context.

See: ClusterPipeline.multi()
Nrb   r   s    rf   r~  ExecutionStrategy.multi  s     	ri   c                    #    g7f)z1
Watch given keys.

See: ClusterPipeline.watch()
Nrb   r  s     rf   r  ExecutionStrategy.watch  r  r  c                    #    g7f)zI
Unwatches all previously specified keys

See: ClusterPipeline.unwatch()
Nrb   r   s    rf   r  ExecutionStrategy.unwatch  r  r  c                    #    g 7fr   rb   r   s    rf   r  ExecutionStrategy.discard&       r  c                    #    g7f)zF
"Unlink a key specified by ``names``"

See: ClusterPipeline.unlink()
Nrb   r  s     rf   r  ExecutionStrategy.unlink*  r  r  c                     g r   rb   r   s    rf   rj  ExecutionStrategy.__len__3      ri   rb   Nr  r  )r  r  r  r  r   r   r   rL   rK   r   r  r  r   r  r   rJ   r  r6  r~  r  r  r  r  rX  rj  r  rb   ri   rf   r  r    s>     4+,8;	  FJ"?C	c  w
23	                ri   r  c            	          \ rS rSrS\SS4S jrSS jrS\\\	4   S	\
SS4S
 jrS r\S\\\	4   SS4S j5       r\ SS\S\S\\
   4S jj5       r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       rS\4S jrSrg)AbstractStrategyi8  r  r^   Nc                     Xl         / U l        g r   )_pipe_command_queue)r   r  s     rf   r   AbstractStrategy.__init__9  s    &*
79ri   r  c                    #    U R                   R                  R                  (       a,  U R                   R                  R                  5       I S h  vN   / U l        U R                   $  N7fr   )r  rU  rj   r   r  r   s    rf   r   AbstractStrategy.initialize=  sK     ::$$00**++66888 zz 9s   AA)A'A)rH  r]   c                     U R                   R                  [        [        U R                   5      /UQ70 UD65        U R                  $ r   )r  r   r  r0  r  rm  s      rf   r   AbstractStrategy.execute_commandC  sA     	""C 3 34FtFvF	
 zzri   c                     SR                  [        [        U5      5      nSU S[        U5       SUR                  S    3nU4UR                  SS -   Ul        g)zC
Provides extra context to the exception prior to it being handled
r   
Command # r  ) of pipeline caused error: r   r   N)r:  maprQ   rS   rH  )r   r"  numberrB  r   msgs         rf   _annotate_exception$AbstractStrategy._annotate_exceptionK  se     hhs8W-.=#5"6 7&^^A./1 	 ).."44	ri   r  c                     g r   rb   r  s     rf   r  AbstractStrategy.mset_nonatomicV  s     	ri   ro  rp  c                    #    g 7fr   rb   rr  s      rf   r  AbstractStrategy.execute\  s
      	r  c                    #    g 7fr   rb   r   s    rf   r6  AbstractStrategy.resetb  r  r  c                     g r   rb   r   s    rf   r~  AbstractStrategy.multif  r  ri   c                    #    g 7fr   rb   r  s     rf   r  AbstractStrategy.watchj  r  r  c                    #    g 7fr   rb   r   s    rf   r  AbstractStrategy.unwatchn  r  r  c                    #    g 7fr   rb   r   s    rf   r  AbstractStrategy.discardr  r  r  c                    #    g 7fr   rb   r  s     rf   r  AbstractStrategy.unlinkv  r  r  c                 ,    [        U R                  5      $ r   )r0  r  r   s    rf   rj  AbstractStrategy.__len__z  s    4&&''ri   )r  r  r  r  )r  r  r  r  r  r   r   r   rL   rK   r   r  r  r   r   rJ   r  r  r   r  r6  r~  r  r  r  r  rX  rj  r  rb   ri   rf   r  r  8  s+   :_ : :4+,8;		5 w
23	 
 FJ"?C	c 
            ( (ri   r  c                      ^  \ rS rSrS\SS4U 4S jjrS\\\4   SS4S jr	 SS	\
S
\
S\\   4S jjr  SSSS\S   S	\
S
\
S\\   4
S jjrS rS rS rS rS rS rSrU =r$ )rY  i~  r  r^   Nc                 $   > [         TU ]  U5        g r   )superr   r   r  r   s     rf   r   PipelineStrategy.__init__  s    ri   r  r  c                 \   U R                   R                  R                  n0 nUR                  5        HA  n[	        UR                  US   5      5      nUR                  U/ 5      R                  U5        MC     UR                  5        H  nU R                  " S/UQ76   M     U R                   $ )Nr   MSET)
r  rU  rp   r  r4   r7  
setdefaultextendr   r  )r   r  rp   slots_pairspairr1  pairss          rf   r  PipelineStrategy.mset_nonatomic  s     **++33MMODGNN4734D""4,33D9 $ !'')E  0%0 * zzri   ro  rp  c                   #    U R                   (       d  / $  U R                  R                  R                  R	                  5       n  U R                  R                  R
                  (       a,  U R                  R                  R                  5       I S h  vN   U R                  U R                  R                  U R                   UUS9I S h  vN U R                  5       I S h  vN   $  NT N N	! [        R                   ac  nUS:  aV  US-  nU R                  R                  R                  5       I S h  vN    [        R                  " S5      I S h  vN     S nAO
UeS nAff = fGM%  ! U R                  5       I S h  vN    f = f7f)N)ro  rp  r   r   r  )r  r  rU  rl   ru  rj   r   _executer6  rZ   rz  r   r   r  )r   ro  rp  r|  r  s        rf   r  PipelineStrategy.execute  s:     ""I	!ZZ66<<HHJN zz00<<"jj77BBDDD!%

11++'5+=	 "/ " $ **,' E$  $66 	 %) '!+"jj77>>@@@%mmD111  	  , **,s   F	/E+ AC. C(7C. C*C. F	"C,#F	(C. *C. ,F	.E%2E 4D75E EE E+ E  E%%E+ +F?F FF	r   rZ   stackr  c                   #    U Vs/ s H6  oUR                   (       a!  [        UR                   [        5      (       d  M4  UPM8     nn0 nU H  nUR                  R	                  SS 5      nU(       a(  UR                  U5      (       d  UR                  U5      n	ODUR                  " UR                  SU06I S h  vN n	U	(       d  [        SUR                   S35      e[        U	5      S:  a  [        SUR                   35      eU	S   n
U
R                  U;  a  U
/ 4XzR                  '   XzR                     S   R                  U5        GM     [        R                  " S UR                  5        5       6 I S h  vN n[!        U5      (       Ga  U(       ai  U Hc  n[        UR                   ["        [$        [&        45      (       d  M/   UR(                  " UR                  0 UR                  D6I S h  vN Ul         Me     U(       a  U H  nUR                   n[        U[        5      (       d  M&  S	R+                  [-        [.        UR                  5      5      nS
UR0                  S-    S[3        U5       SUR                   3nU4UR                  SS  -   Ul        Ue   UR5                  5       nUbc  UR7                  UR                  5      nUbE  US    H<  n[9        UR                   5      [:        R<                  ;   d  M,  UR?                  5           O   U Vs/ s H  oUR                   PM     sn$ s  snf  GN} GN GNJ! [         a  nXl          S nAGM  S nAff = fs  snf 7f)Nr_  rG  rm  rn  r   zToo many targets for command r   c              3   x   #    U  H0  n[         R                  " US    R                  US   5      5      v   M2     g7f)r   r   N)r   rp  r  rN  s     rf   rs  ,PipelineStrategy._execute.<locals>.<genexpr>  s8      *D ##DG$<$<T!W$EFF*s   8:r   r  r  r  ) r  ra  r   r]   rd   rc  rj  rQ  rH  rC   r0  r   r   r   rx  r   anyrH   rB   r8   r  r:  r  rQ   r  rS   r  r   rh  rZ   rz  rw  )r   r   r  ro  rp  r   todori  r}  r_  r   errorsr  r  rB  r  default_cluster_noder   s                     rf   r  PipelineStrategy._execute  s     !
 C

jY6WC5 	 
 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(: ;  -g 67 899?G 
 (+fv{{12&>$   $*#:#:#< 
 $/$yy)=)B)BC+
  ,A  

+|/N/NN"779!  / ',,es

e,,W
 
*  ) +)*JJ+F -s   M!3L/L/A3M!7L48C M!8L79A	M!)L=0L:1	L=:/M!-CM!?M!M,	M!7M!:L==
MMM!MM!c                    #    / U l         g7frz  r  r   s    rf   r6  PipelineStrategy.reset  s      !s   	c                     [        S5      e)Nz@method multi() is not supported outside of transactional contextrC   r   s    rf   r~  PipelineStrategy.multi  s    #N
 	
ri   c                     #    [        S5      e7f)Nz@method watch() is not supported outside of transactional contextr  r  s     rf   r  PipelineStrategy.watch  s     #N
 	
   c                     #    [        S5      e7f)NzBmethod unwatch() is not supported outside of transactional contextr  r   s    rf   r  PipelineStrategy.unwatch       #P
 	
r  c                     #    [        S5      e7f)NzBmethod discard() is not supported outside of transactional contextr  r   s    rf   r  PipelineStrategy.discard  r  r  c                 h   #    [        U5      S:w  a  [        S5      eU R                  SUS   5      $ 7f)Nr   z>unlinking multiple keys is not implemented in pipeline commandUNLINKr   )r0  rC   r  r  s     rf   r  PipelineStrategy.unlink  s9     u:?'P  ##HeAh77s   02r  r  )r  r  r  r  r  r   r   rJ   rK   r  r  r   r   r  r  r6  r~  r  r  r  r  r  __classcell__r   s   @rf   rY  rY  ~  s    _  w
23	  GK"?C	cH  $#'R-R- %&R- 	R-
 !R- 
cR-h!







8 8ri   rY  c                   ~  ^  \ rS rSrS1rSS1r1 Skr\\4r	\
\\\4rS\SS4U 4S jjrS\\\4   4S	 jrS
\\\4   S\SS4S jrS
\\\4   S\S\4U 4S jjrS rS rS rS\S\4S jrS rS r S\!\"\4   SS4S jr# S(S\$S\$S\%\   4S jjr&S\%S   S\$4S jr'S\%S   S\$4S  jr(S! r)S" r*S# r+S$ r,S% r-S& r.S'r/U =r0$ ))rZ  i(  UNWATCHWATCH>   EXECDISCARDr  r  r^   Nc                 P  > [         TU ]  U5        SU l        SU l        [	        5       U l        S U l        S U l        SU l        [        U R                  R                  R                  5      U l        U R                  R                  [        R                   U R"                  -   5        g )NF)r  r   _explicit_transaction	_watchingset_pipeline_slots_transaction_node_transaction_connection
_executingr   r  rU  rl   _retryr   rZ   rz  SLOT_REDIRECT_ERRORSr  s     rf   r   TransactionStrategy.__init__4  s    %*"),8<=A$4::44::;++++d.G.GG	
ri   c                 d   U R                   (       d  [        S5      eU R                  R                  R                  R                  [        U R                   5      S   S5      nXl        U R                  (       d   U R                  R                  5       nX l        U R                  U R                  4$ )a?  
Find a connection for a pipeline transaction.

For running an atomic transaction, watch keys ensure that contents have not been
altered as long as the watch commands for those keys were sent over the same
connection. So once we start watching a key, we fetch a connection to the
node that owns that slot and reuse it.
z:At least a command with a key is needed to identify a noder   F)
r  rC   r  rU  rr   rO  r   r  r  r  )r   r   r  s      rf   *_get_client_and_connection_for_transaction>TransactionStrategy._get_client_and_connection_for_transactionA  s     ##'L  !JJ55CCVV%%&q)5
 "&++%)%;%;%N%N%PJ+5(%%t'C'CCCri   rH  r]   r   c                    ^ ^^^^ S mS mUUUUU 4S jn[         R                  " US9nUR                  5         UR                  5         T(       a  TeT$ )Nc                     >  [         R                  " TR                  " T0 TD65      mg ! [         a  n U m S n A g S n A ff = fr   )r   runrq  r   )r  rH  r  r]   r  r   s    rf   runner3TransactionStrategy.execute_command.<locals>.runnera  s;    ";;t'<'<d'Mf'MN s   &* 
A ;A )target)	threadingThreadstartr:  )r   rH  r]   r"  threadr  r  s   ```  @@rf   r  #TransactionStrategy.execute_command\  sH    	 	 !!0Kri   c                 4  >#    U R                   R                  R                  (       a,  U R                   R                  R                  5       I S h  vN   S nUS   U R                  ;  a+  U R                   R                  R
                  " U6 I S h  vN nU R                  (       d  US   U R                  ;   a  U R                  (       d  US   S:X  a  U R                  5         UbG  U R                  (       a  X0R                  ;  a  [        S5      eU R                  R                  U5        O%US   U R                  ;  a  [        SUS    S35      eU R                  " U0 UD6$ Ub  U R                  R                  U5        [        TU ]@  " U0 UD6$  GNB GN7f)Nr   r  z0Cannot watch or send commands on different slotsz)Cannot identify slot number for command: z(,it cannot be triggered in a transaction)r  rU  rj   r   NO_SLOTS_COMMANDSrP  r  IMMEDIATE_EXECUTE_COMMANDSr  _validate_watchr  r=   addrC   _immediate_execute_commandr  r  )r   rH  r]   slot_numberr   s       rf   rq  $TransactionStrategy._execute_commandr  sm     ::$$00**++66888%)7$000 $

 9 9 I I4 PPK NNd1g)H)HH,,Aw'!$$&&''K?S?S,S3J  $$((5a 6 66+?Qy I> > 
 22DCFCC&$$((57*D;F;;= 9 Qs%   AFF?FFDFFc                 J    U R                   (       a  [        S5      eSU l        g )N"Cannot issue a WATCH after a MULTIT)r  rD   r  r   s    rf   r-  #TransactionStrategy._validate_watch  s    %%ABBri   c                 |   ^ ^^#    T R                   R                  UUU 4S jT R                  5      I S h  vN $  N7f)Nc                  (   > TR                   " T 0 TD6$ r   ) _get_connection_and_send_command)rH  optionsr   s   rf   r   @TransactionStrategy._immediate_execute_command.<locals>.<lambda>  s    D994K7Kri   r  r
  _reinitialize_on_error)r   rH  r8  s   ```rf   r/  .TransactionStrategy._immediate_execute_command  s3     [[00K''
 
 	
 
   0<:<c                 v   #    U R                  5       u  p4U R                  " XCUS   /UQ70 UD6I S h  vN $  N7fr   )r  _send_command_parse_response)r   rH  r8  
redis_noder  s        rf   r7  4TransactionStrategy._get_connection_and_send_command  sL     !%!P!P!R
66DG
.2
6=
 
 	
 
s   0979r  r@  c                    #    UR                   " U6 I Sh  vN   UR                  " X40 UD6I Sh  vN nX0R                  ;   a  SU l        U$  N7 N7f)z'
Send a command and parse the response
NF)r	  r  UNWATCH_COMMANDSr  )r   r  r@  command_namerH  r8  outputs          rf   r?  0TransactionStrategy._send_command_parse_response  sS      %%t,,,!00UWUU000"DN 	-Us   AAAAAAc                 j  #    U R                   (       a5  [        U5      U R                  ;   a  U R                  (       a  [	        S5      e[        U5      U R                  ;   d  [        U5      U R
                  ;   Ga-  U R                  (       a  S U l        U R                  R                  =R                  S-  sl	        U R                  R                  R                  (       a  U R                  R                  R                  U R                  R                  R                  -  S:X  a>  U R                  R                  R                  R                  5       I S h  vN   SU l	        OD[        U[        5      (       a/  U R                  R                  R                  R                  U5        SU l        g  NX7f)Nz-Slot rebalancing occurred while watching keysr   r   F)r  rh  r  r  rI   CONNECTION_ERRORSr  r  rU  rt   ru   rr   r   ra  r8   r#  r  s     rf   r;  *TransactionStrategy._reinitialize_on_error  s1    >>E{d777DOO !PQQ K4444E{d444++/3,JJ%%::a?:

))<<JJ--BB**++>>? jj//==HHJJJ,-)eX..JJ--;;RR   Ks   EF3F1AF3c                     [        X5       HE  u  p4[        U[        5      (       d  M  U R                  X4R                  S-   UR
                  5        Ue   g)z(
Raise the first exception on the stack
r   N)ry  ra  r   r  r  rH  )r   	responsesr  rr   s        rf   _raise_first_error&TransactionStrategy._raise_first_error  sD     )+FA!Y''((LL1,<chhG ,ri   r  r  c                     [        S5      e)Nz1Method is not supported in transactional context.)NotImplementedErrorr  s     rf   r  "TransactionStrategy.mset_nonatomic  s     ""UVVri   ro  rp  c                    #    U R                   nU(       d$  U R                  (       a  U R                  (       d  / $ U R                  X15      I S h  vN $  N7fr   )r  r  r  !_execute_transaction_with_retries)r   ro  rp  r  s       rf   r  TransactionStrategy.execute  s?      ##dnnD4H4HI;;ERRRRs   AAAAr  r  c                 |   ^ ^^#    T R                   R                  UU U4S jT R                  5      I S h  vN $  N7f)Nc                  (   > TR                  TT 5      $ r   )_execute_transaction)ro  r   r  s   rf   r   GTransactionStrategy._execute_transaction_with_retries.<locals>.<lambda>  s    D--e^Dri   r:  )r   r  ro  s   ```rf   rS  5TransactionStrategy._execute_transaction_with_retries  s5      [[00D''
 
 	
 
r=  c           	        #    [        U R                  5      S:  a  [        S5      eSU l        U R	                  5       u  p4[        [        SS5      /U[        SS5      /5      nU Vs/ s H%  n[        UR                  ;  d  M  UR                  PM'     nnUR                  U5      nUR                  U5      I S h  vN   / n UR                  US5      I S h  vN   [#        U R$                  5       HY  u  p[        UR                  ;   a%  UR                  XR                  [           45        M>   UR                  US5      I S h  vN nM[     S n UR                  US5      I S h  vN nSU l        SU l        Uc  [-        S	5      eU H  u  pUR/                  X5        M     [        U5      [        U R$                  5      :w  aK  [1        S
R3                  U R$                   Vs/ s H  oUR                  S   PM     sn[        U5      5      5      eU(       d  [        U5      S:  a  U R5                  UU R$                  5        / n[7        XR$                  5       H  u  nn[9        U[:        5      (       dg  UR                  S   nUU R<                  R>                  R@                  ;   a4  U R<                  R>                  R@                  U   " U40 UR                  D6nUR                  U5        M     U$ s  snf  GN= GN#! [         a/  n	U R                  U	SS5        UR                  U	5         S n	A	GNUS n	A	fU R                    a  n
U R                  U
SS5        e S n
A
ff = f GN! U R&                   a<  nU R                  XS-   UR                  5        UR                  U5         S nAGM  S nAfU R                    a%  n
U R                  XS-   UR                  5        e S n
A
f[         a<  n	U R                  XS-   UR                  5        UR                  U	5         S n	A	GM0  S n	A	ff = f GN! [(         a    U(       a  US   ee f = fs  snf 7f)Nr   zDAll keys involved in a cluster transaction must map to the same slotTr   MULTIr  r  FzWatched variable changed.zeUnexpected response length for cluster pipeline EXEC. Command stack was {} but response had length {})!r0  r  r=   r  r  r   r  r$   r]   rH  r  r  r  rE   r  r   rH  	enumerater  r  r?   r  rI   insertr@   formatrM  ry  ra  r   r  rU  rv   )r   r  ro  r@  r  cr  packed_commandsr  r  cluster_errorrB  rB  r  
slot_errorr  datarL  r   rD  s                       rf   rW  (TransactionStrategy._execute_transaction  s     t##$q(+V  !%!P!P!R
Q()Q'(

 %*LEq^188-KFAFFEL$228<,,_===	++J@@@ $D$7$78JA/q.."@AB
%(77
CHHA 9  	'66z6JJH   899 DAOOA!  x=C 3 344&CCI6(,(;(;<(;1VVAY(;<c(mD  S[1_#### ($7$78FAsa++"xx{4::#<#<#O#OO

11DD\R ZZA KKN 9 c M= A 	$$Q73MM!%% 	$$]Aw?	 I00 .,,ZQMMM*---- ,,]E7<<P$ %,,QAw||DMM!$$% K 	Qi	* =s   A%Q'K2K2'Q:K7;QK= K:K= AQ0M#M M#
QP, &P)'P, +A8Q#Q;C=Q:K= =
M$L1+Q1MMMQ M##P&30N*#Q*P&= OP&*0P!Q!P&&Q)P, ,QQc                 4  #    / U l         U R                  (       a   U R                  (       aE  U R                  R                  S5      I S h  vN   U R                  R	                  5       I S h  vN   U R
                  R                  U R                  5        S U l        S U l        SU l        SU l	        [        5       U l        SU l        g  N~ N^! U R                   a7    U R                  (       a#  U R                  R                  5       I S h  vN     Nvf = f7f)Nr  F)r  r  r  r	  r
  r  r  rH  r  r  r  r  r  r   s    rf   r6  TransactionStrategy.reset[	  s       ''D>> 66CCINNN66DDFFF &&..t/K/KL/3, "&%*""u! OF
 )) D//66AACCCDsX   D/C C
!C -C.0C ,D
C C >DDDDDDc                     U R                   (       a  [        S5      eU R                  (       a  [        S5      eSU l         g )Nz"Cannot issue nested calls to MULTIz:Commands without an initial WATCH have already been issuedT)r  rD   r  r   s    rf   r~  TransactionStrategy.multiw	  s:    %%ABBL  &*"ri   c                 |   #    U R                   (       a  [        S5      eU R                  " S/UQ76 I S h  vN $  N7f)Nr3  r  )r  rD   r  r  s     rf   r  TransactionStrategy.watch	  s6     %%ABB))':E::::s   3<:<c                 d   #    U R                   (       a  U R                  S5      I S h  vN $ g N7f)Nr  T)r  r  r   s    rf   r  TransactionStrategy.unwatch	  s(     >>--i888 9s   &0.0c                 @   #    U R                  5       I S h  vN   g  N7fr   ra  r   s    rf   r  TransactionStrategy.discard	  rc  r   c                 0   #    U R                   " S/UQ76 $ 7f)Nr  )r  r  s     rf   r  TransactionStrategy.unlink	  s     ##H5u55s   )	r  r  r  r  r  r  r  r  rt   r  )1r  r  r  r  r+  r,  rC  r8   rB   r  r<   OSErrorr:   rF   rH  r  r   r   rX   r   r  r   rL   rK   r   r  rq  r-  r/  r7  r?  r;  rM  r   rJ   r  r  r   r  rS  rW  r6  r~  r  r  r  r  r  r
  r  s   @rf   rZ  rZ  (  s   "")9!55$j1	
_ 
 
D	{J&	'D6U4+;%<  PU ,"<4+,"<8;"<	"<H

  & :Ww
23W	W GKS"S?CS	cS
+,
>B
b+,b>BbH 8*;6 6ri   rZ  )~r   r  r  r  r%  r  r  abcr   r   r   	itertoolsr   typingr   r   r	   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   redis.asyncio.lockr   redis.asyncio.retryr    redis.auth.tokenr!   redis.backoffr"   r#   redis.clientr$   r%   r&   redis.clusterr'   r(   r)   r*   r+   r,   r-   r.   r/   r0   redis.commandsr1   r2   	redis.crcr3   r4   redis.credentialsr5   redis.eventr6   r7   redis.exceptionsr8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   redis.typingrJ   rK   rL   redis.utilsrM   rN   rO   rP   rQ   rR   rS   ra   rT   rU   rV   rb  rW   rZ   rX   r   r  rB  replacelowersetattrr  r  r  rY  rZ  rb   ri   rf   <module>r     s          #     " 8 
 3 I I # % + A D D   D 8 0 L    ( 3 2   77JJKC](;T#}BT=U
p="68Q pfX Xvs sl	V@m%9;T V@r )Gooc3'--/G""OW&<W&EF )@ @a aHC(( C(Lg8' g8Th6* h6ri   