
    Ii7                        S SK r S SKrS SKrS SKJrJrJrJrJrJ	r	J
r
  S SKJr  S SKJrJrJrJr  S SKJr  S SKJrJrJrJr  S SKJr   " S S	\5      r " S
 S\5      r " S S\5      r " S S\\5      r " S S\5      r " S S\5      r g)    N)AsyncIteratorIterableMappingOptionalSequenceTupleType)Redis)
ConnectionConnectionPool
EncodableTSSLConnection)AsyncSentinelCommands)ConnectionErrorReadOnlyErrorResponseErrorTimeoutError)str_if_bytesc                       \ rS rSrSrg)MasterNotFoundError    N__name__
__module____qualname____firstlineno____static_attributes__r       </venv/lib/python3.13/site-packages/redis/asyncio/sentinel.pyr   r          r   r   c                       \ rS rSrSrg)SlaveNotFoundError   r   Nr   r   r   r    r#   r#      r!   r   r#   c                      ^  \ rS rSrU 4S jrS rU 4S jrS rS r  SSSS	.S
\	S\
\   S\
\   S\
\	   4U 4S jjjjrSrU =r$ )SentinelManagedConnection   c                 R   > UR                  S5      U l        [        TU ]  " S0 UD6  g )Nconnection_poolr   )popr)   super__init__)selfkwargs	__class__s     r    r,   "SentinelManagedConnection.__init__   s%    %zz*;<"6"r   c                     SU R                   R                   SU R                   R                   3nU R                  (       a   SU R                   SU R                   3nX-  nUS-   $ )N<.z,host=z,port=z)>)r/   r   r   hostport)r-   s	host_infos      r    __repr__"SentinelManagedConnection.__repr__   s[    ))*!DNN,C,C+DE99 6$))=INA4xr   c                 .  >#    Uu  U l         U l        [        TU ]  5       I S h  vN   U R                  R
                  (       aJ  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 g  Nj N8 N7f)NPINGPONGzPING failed)
r4   r5   r+   connectr)   check_connectionsend_commandr   read_responser   )r-   addressr/   s     r    
connect_to$SentinelManagedConnection.connect_to&   s     &	49go00##F+++$"4"4"6676A%m44 B 1 	 +6s3   !BB3BBB5B6BBBc                   #    U R                   (       a  g U R                  R                  (       a:  U R                  U R                  R	                  5       I S h  vN 5      I S h  vN   g U R                  R                  5         S h  vN n U R                  U5      I S h  vN s  $  NP NF N$ N! [         a     M:  f = f
 [        e7fN)_readerr)   	is_masterrB   get_master_addressrotate_slavesr   r#   )r-   slaves     r    _connect_retry(SentinelManagedConnection._connect_retry.   s     <<))//(<(<(O(O(Q"QRRR#33AAC e!%!777	 #RR7&   D
 %$sx   AC	B)C	$B+%C	CB-	CC	B1"B/#B1&C	+C	-C/B11
B?;C	>B??
C	c                 l   #    U R                   R                  U R                  S 5      I S h  vN $  N7f)Nc                 .    [         R                  " S5      $ )Nr   )asynciosleep)errors    r    <lambda>3SentinelManagedConnection.connect.<locals>.<lambda>>   s    '--*r   )retrycall_with_retryrK   r-   s    r    r=   !SentinelManagedConnection.connect;   s2     ZZ//*
 
 	
 
s   +424FT)disconnect_on_errorpush_requestdisable_decodingtimeoutrX   rY   c                   >#     [         TU ]  UUUUS9I S h  vN $  N! [         aA    U R                  R                  (       a$  U R                  5       I S h  vN    [        S5      ee f = f7f)N)rZ   r[   rX   rY   z"The previous master is now a slave)r+   r@   r   r)   rG   
disconnectr   )r-   rZ   r[   rX   rY   r/   s        r    r@   'SentinelManagedConnection.read_responseA   sx     	.!1$7)	 /      		##-- oo'''%&JKK		s1   A-  A- 8A*AA**A-)r)   r4   r5   )FN)r   r   r   r   r,   r8   rB   rK   r=   boolr   floatr@   r   __classcell__r/   s   @r    r&   r&      sm    #5%
 "'#'
 04', %
 &e_ tn r   r&   c                       \ rS rSrSrg)SentinelManagedSSLConnection\   r   Nr   r   r   r    rd   rd   \   r!   r   rd   c                   f   ^  \ rS rSrSrU 4S jrS rU 4S jrS\4U 4S jjr	S r
S	\4S
 jrSrU =r$ )SentinelConnectionPool`   z
Sentinel backed connection pool.

If ``check_connection`` flag is set to True, SentinelManagedConnection
sends a PING command right after establishing the connection.
c                 h  > UR                  SUR                  SS5      (       a  [        O[        5      US'   UR                  SS5      U l        UR                  SS5      U l        [        TU ]  " S0 UD6  [        R                  " U 5      U R                  S'   Xl        X l        S U l        S U l        g )	Nconnection_classsslFrG   Tr>   r)   r   )getr*   rd   r&   rG   r>   r+   r,   weakrefproxyconnection_kwargsservice_namesentinel_managermaster_addressslave_rr_counter)r-   rp   rq   r.   r/   s       r    r,   SentinelConnectionPool.__init__h   s    %+ZZ ::eU++ -.&
!"  K6 &

+=u E"6"4;MM$4G01( 0" $r   c           	          SU R                   R                   SU R                   R                   SU R                   SU R                  =(       a    S=(       d    S S3	$ )Nr2   r3   z	(service=(masterrJ   z))>)r/   r   r   rp   rG   rV   s    r    r8   SentinelConnectionPool.__repr__z   sV    ))*!DNN,C,C+D))*!DNN,Gx,R7+SSVX	
r   c                 >   > [         TU ]  5         S U l        S U l        g rE   )r+   resetrr   rs   )r-   r/   s    r    rz   SentinelConnectionPool.reset   s    " $r   
connectionc                    > U R                   (       + =(       d8    U R                   =(       a%    U R                  UR                  UR                  4:H  nU=(       a    [        TU ]  U5      $ rE   )rG   rr   r4   r5   r+   owns_connection)r-   r|   checkr/   s      r    r~   &SentinelConnectionPool.owns_connection   sR    NN" 
NNXt22z
6XX 	 <0<<r   c                    #    U R                   R                  U R                  5      I S h  vN nU R                  (       a-  U R                  U:w  a  Xl        U R                  SS9I S h  vN   U$  ND N7f)NF)inuse_connections)rq   discover_masterrp   rG   rr   r]   )r-   rr   s     r    rH   )SentinelConnectionPool.get_master_address   sf     #44DDTEVEVWW>>""n4&4# ooo>>> X ?s!   )A4A0=A4)A2*A42A4returnc                
  #    U R                   R                  U R                  5      I Sh  vN nU(       a  U R                  c(  [        R
                  " S[        U5      S-
  5      U l        [        [        U5      5       H6  nU R                  S-   [        U5      -  U l        XR                     nU7v   M8      U R                  5       I Sh  vN 7v   [        SU R                  < 35      e N N"! [         a     N)f = f7f)zRound-robin slave balancerNr      zNo slave found for )rq   discover_slavesrp   rs   randomrandintlenrangerH   r   r#   )r-   slaves_rJ   s       r    rI   $SentinelConnectionPool.rotate_slaves   s     ,,<<T=N=NOO$$,(.q#f+/(J%3v;')-)>)>)Bc&k(Q%445 (
	//111 !#6t7H7H6K!LMM P 2" 		sF   )DC/BD;C3 C1C3 D1C3 3
D =D?D  D)r>   rG   rr   rq   rp   rs   )r   r   r   r   __doc__r,   r8   rz   r   r~   rH   r   rI   r   ra   rb   s   @r    rg   rg   `   s<    %$
%
=* =N] N Nr   rg   c                       \ rS rSrSr  SS jrS rS rS\S\	S	\
4S
 jrS\	4S jrS\\   S	\\\\4      4S jrS\	S	\\\\4      4S jr\\4S\	S\\   S\\   4S jjr\\4S\	S\\   S\\   4S jjrSrg)Sentinel   a*  
Redis Sentinel cluster client

>>> from redis.sentinel import Sentinel
>>> sentinel = Sentinel([('localhost', 26379)], socket_timeout=0.1)
>>> master = sentinel.master_for('mymaster', socket_timeout=0.1)
>>> await master.set('foo', 'bar')
>>> slave = sentinel.slave_for('mymaster', socket_timeout=0.1)
>>> await slave.get('foo')
b'bar'

``sentinels`` is a list of sentinel nodes. Each node is represented by
a pair (hostname, port).

``min_other_sentinels`` defined a minimum number of peers for a sentinel.
When querying a sentinel, if it doesn't meet this threshold, responses
from that sentinel won't be considered valid.

``sentinel_kwargs`` is a dictionary of connection arguments used when
connecting to sentinel instances. Any argument that can be passed to
a normal Redis connection can be specified here. If ``sentinel_kwargs`` is
not specified, any socket_timeout and socket_keepalive options specified
in ``connection_kwargs`` will be used.

``connection_kwargs`` are keyword arguments that will be used when
establishing a connection to a Redis server.
Nc           
          Uc<  UR                  5        VVs0 s H  u  pVUR                  S5      (       d  M  XV_M!     nnnX0l        U VVs/ s H  u  px[        SXxS.U R                  D6PM     snnU l        X l        X@l        g s  snnf s  snnf )Nsocket_)r4   r5   r   )items
startswithsentinel_kwargsr
   	sentinelsmin_other_sentinelsro   )	r-   r   r   r   ro   kvhostnamer5   s	            r    r,   Sentinel.__init__   s     "!2!8!8!:!:all9>U!:    / #,
"+ CxCd.B.BC"+
 $7 !2

s   BB#B
c           
        #    [        UR                  SS5      5      nSUR                  5       ;   a  UR                  S5        U(       a9  [        R
                  " U R                  5      R                  " U0 UD6I Sh  vN   gU R                   Vs/ s H)  n[        R                  " UR                  " U0 UD65      PM+     nn[        R                  " U6 I Sh  vN   g Nas  snf  N7f)z
Execute Sentinel command in sentinel nodes.
once - If set to True, then execute the resulting command on a single
       node at random, rather than across the entire sentinel cluster.
onceFNT)r_   rl   keysr*   r   choicer   execute_commandrO   Taskgather)r-   argsr.   r   sentineltaskss         r    r   Sentinel.execute_command   s      FJJvu-.V[[]"JJv--/??PPPP  !% .H X55tFvFG .   ..%((( Q )s0   A;C(=C>C(0C!C(C&C(!C(c                 &   / nU R                    HG  nUR                  UR                  R                  S    SUR                  R                  S    35        MI     SU R                   SU R                  R
                   SSR                  U5       S3$ )	Nr4   :r5   r2   r3   z(sentinels=[,z])>)r   appendr)   ro   r/   r   join)r-   sentinel_addressesr   s      r    r8   Sentinel.__repr__   s    H%%++==fEFa++==fEFH ' q!8!8 9388$678=	
r   staterp   r   c                 j    US   (       a  US   (       d
  US   (       a  gUS   U R                   :  a  gg)NrG   is_sdownis_odownFznum-other-sentinelsT)r   )r-   r   rp   s      r    check_master_stateSentinel.check_master_state   s5    [!U:%6%
:K&'$*B*BBr   c                 6  #    [        5       n[        U R                  5       H  u  p4 UR                  5       I Sh  vN nUR                  U5      nU(       d  M8  U R                  Xq5      (       d  MP  UU R                  S   sU R                  S'   U R                  U'   US   US   4s  $    Sn[        U5      S:  a  SSR                  U5       3n[        S	U< U 35      e N! [        [
        4 a"  nUR                  U SU< 35         SnAM  SnAff = f7f)
z
Asks sentinel servers for the Redis master's address corresponding
to the service labeled ``service_name``.

Returns a pair (address, port) or raises MasterNotFoundError if no
master is found.
Nz - r   ipr5    z : z, zNo master found for )list	enumerater   sentinel_mastersr   r   r   rl   r   r   r   r   )	r-   rp   collected_errorssentinel_nor   masterser   
error_infos	            r    r   Sentinel.discover_master  s      6%.t~~%>!K ( 9 9 ;; KK-Eu00EE NN1% ?q!4>>+#> T{E&M11 &? 
 1$tyy)9:;<J!$88H"UVV! <#\2  ''8*Cu(=>sK   %DC$C"C$ DD2A0D"C$$D4DDDDr   c                 z    / nU H2  nUS   (       d
  US   (       a  M  UR                  US   US   45        M4     U$ )z1Remove slaves that are in an ODOWN or SDOWN stater   r   r   r5   )r   )r-   r   slaves_aliverJ   s       r    filter_slavesSentinel.filter_slaves  sH     EZ E*$5teFm <=  r   c                    #    U R                    H9  n UR                  U5      I Sh  vN nU R                  U5      nU(       d  M7  Us  $    / $  N&! [        [        [        4 a     MY  f = f7f)z;Returns a list of alive slaves for service ``service_name``N)r   sentinel_slavesr   r   r   r   )r-   rp   r   r   s       r    r   Sentinel.discover_slaves*  sn      H'77EE ''/Fv ' 	 F#]LA s=   A,AAAA,A,AA)%A,(A))A,redis_classconnection_pool_classc                     SUS'   [        U R                  5      nUR                  U5        U" X40 UD6nUR                  U5      $ )a  
Returns a redis client instance for the ``service_name`` master.

A :py:class:`~redis.sentinel.SentinelConnectionPool` class is
used to retrieve the master's address before establishing a new
connection.

NOTE: If the master's address has changed, any cached connections to
the old master are closed.

By default clients will be a :py:class:`~redis.Redis` instance.
Specify a different class to the ``redis_class`` argument if you
desire something different.

The ``connection_pool_class`` specifies the connection pool to
use.  The :py:class:`~redis.sentinel.SentinelConnectionPool`
will be used by default.

All other keyword arguments are merged with any connection_kwargs
passed to this class and passed to the connection pool as keyword
arguments to be used to initialize Redis connections.
TrG   dictro   update	from_poolr-   rp   r   r   r.   ro   r)   s          r    
master_forSentinel.master_for8  sN    : #{ !7!78  (/XFWX$$_55r   c                     SUS'   [        U R                  5      nUR                  U5        U" X40 UD6nUR                  U5      $ )a  
Returns redis client instance for the ``service_name`` slave(s).

A SentinelConnectionPool class is used to retrieve the slave's
address before establishing a new connection.

By default clients will be a :py:class:`~redis.Redis` instance.
Specify a different class to the ``redis_class`` argument if you
desire something different.

The ``connection_pool_class`` specifies the connection pool to use.
The SentinelConnectionPool will be used by default.

All other keyword arguments are merged with any connection_kwargs
passed to this class and passed to the connection pool as keyword
arguments to be used to initialize Redis connections.
FrG   r   r   s          r    	slave_forSentinel.slave_for]  sN    0 ${ !7!78  (/XFWX$$_55r   )ro   r   r   r   )r   N)r   r   r   r   r   r,   r   r8   r   strr_   r   r   r   r   r   r   r   r   r   r
   rg   r	   r   r   r   r   r   r    r   r      s    > 	3,(

 C D W# W:	w'		%
J./	0		%
J./	0" $)>T	#6#6 %[#6  $$:;	#6P $)>T	66 %[6  $$:;	6 6r   r   )!rO   r   rm   typingr   r   r   r   r   r   r	   redis.asyncio.clientr
   redis.asyncio.connectionr   r   r   r   redis.commandsr   redis.exceptionsr   r   r   r   redis.utilsr   r   r#   r&   rd   rg   r   r   r   r    <module>r      s       T T T &  1 X X $	/ 		 	?
 ?D	#<m 	DN^ DNNT6$ T6r   