
    ph:                        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\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TimeoutErrorc                       \ rS rSrSrg)MasterNotFoundError    N__name__
__module____qualname____firstlineno____static_attributes__r       P/home/james-whalen/.local/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S 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        U R                  U R                  R                  SS9I S h  vN   g  N7f)NF)check_healthretry_socket_connect)r3   r4   connect_check_healthr(   check_connection)r,   addresss     r   
connect_to$SentinelManagedConnection.connect_to*   sB     &	49''-->>!& ( 
 	
 	
s   7A?A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_masterr?   get_master_addressrotate_slavesr   r"   )r,   slaves     r   _connect_retry(SentinelManagedConnection._connect_retry1   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>A   s    '--*r   )retrycall_with_retryrH   r,   s    r   connect!SentinelManagedConnection.connect>   s2     ZZ//*
 
 	
 
s   +424FT)disconnect_on_errorpush_requestdisable_decodingtimeoutrV   rW   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)rX   rY   rV   rW   z"The previous master is now a slave)r*   read_responser   r(   rD   
disconnectr   )r,   rX   rY   rV   rW   r.   s        r   r[   'SentinelManagedConnection.read_responseD   sx     	.!1$7)	 /      		##-- oo'''%&JKK		s1   A-  A- 8A*AA**A-)r(   r3   r4   )FN)r   r   r   r   r+   r7   r?   rH   rT   boolr   floatr[   r   __classcell__r.   s   @r   r%   r%      sm    #
%
 "'#'
 04', %
 &e_ tn r   r%   c                       \ rS rSrSrg)SentinelManagedSSLConnection_   r   Nr   r   r   r   rc   rc   _   r    r   rc   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$ )SentinelConnectionPoolc   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sslFrD   Tr=   r(   r   )getr)   rc   r%   rD   r=   r*   r+   weakrefproxyconnection_kwargsservice_namesentinel_managermaster_addressslave_rr_counter)r,   ro   rp   r-   r.   s       r   r+   SentinelConnectionPool.__init__k   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	$ )Nr1   r2   z	(service=(masterrG   z))>)r.   r   r   ro   rD   rS   s    r   r7   SentinelConnectionPool.__repr__}   sV    ))*!DNN,C,C+D))*!DNN,Gx,R7+SSVX	
r   c                 >   > [         TU ]  5         S U l        S U l        g rB   )r*   resetrq   rr   )r,   r.   s    r   ry   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      $ rB   )rD   rq   r3   r4   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)rp   discover_masterro   rD   rq   r\   )r,   rq   s     r   rE   )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 )rp   discover_slavesro   rr   randomrandintlenrangerE   r   r"   )r,   slaves_rG   s       r   rF   $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=   rD   rq   rp   ro   rr   )r   r   r   r   __doc__r+   r7   ry   r   r}   rE   r   rF   r   r`   ra   s   @r   rf   rf   c   s<    %$
%
=* =N] N Nr   rf   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  pgUR                  S5      (       d  M  Xg_M!     nnnX0l        U VV	s/ s H  u  p[        SXS.U R                  D6PM     sn	nU l        X l        XPl        X@l        g s  snnf s  sn	nf )Nsocket_)r3   r4   r   )items
startswithsentinel_kwargsr
   	sentinelsmin_other_sentinelsrn   _force_master_ip)
r,   r   r   r   force_master_iprn   kvhostnamer4   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[        UR                  SS5      5      nU(       aM  [        R                  " U R                  5      R
                  " U0 UD6I Sh  vN nU(       a  U/$ U(       a  S$ S$ 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 nU(       a  U$ [        U5      $  Ns  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.
onceFreturn_responsesNT)
r^   r)   r   choicer   execute_commandrL   Taskgatherall)	r,   argsr-   r   r   responsesentineltasks	responsess	            r   r   Sentinel.execute_command   s      FJJvu-.  

+=u EF#]]4>>:JJ H   z!'t2U2 !NN
* LL114B6BC* 	 
 "..%00	9~#
 1s0   A1D3C<4'D0C>D#D$D>D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$ )	Nr3   :r4   r1   r2   z(sentinels=[,z])>)r   appendr(   rn   r.   r   join)r,   sentinel_addressesr   s      r   r7   Sentinel.__repr__   s    H%%++==fEFa++==fEFH ' q!8!8 9388$678=	
r   statero   r   c                 j    US   (       a  US   (       d
  US   (       a  gUS   U R                   :  a  gg)NrD   is_sdownis_odownFznum-other-sentinelsT)r   )r,   r   ro   s      r   check_master_stateSentinel.check_master_state  s5    [!U:%6%
:K&'$*B*BBr   c                 l  #    [        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 R                  b  U R                  OUS   nXS   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G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   ipr4    z : z, zNo master found for )list	enumerater   sentinel_mastersr   r   r   rk   r   r   r   r   r   )
r,   ro   collected_errorssentinel_nor   masterser   r   
error_infos
             r   r   Sentinel.discover_master  s9      6%.t~~%>!K ( 9 9 ;; KK-Eu00EE NN1% ?q!4>>+#> ,,8 ))t 
 =((' &?* 
 1$tyy)9:;<J!$88H"UVV- <#\2  ''8*Cu(=>sK   %D4C>C<C> D4D42B
D4<C>>D1D,%D4,D11D4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   r4   )r   )r,   r   slaves_aliverG   s       r   filter_slavesSentinel.filter_slaves6  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,   ro   r   r   s       r   r   Sentinel.discover_slavesA  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      $ )am  
Returns a redis client instance for the ``service_name`` master.
Sentinel client will detect failover and reconnect Redis clients
automatically.

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.
TrD   dictrn   update	from_poolr,   ro   r   r   r-   rn   r(   s          r   
master_forSentinel.master_forO  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.
FrD   r   r   s          r   	slave_forSentinel.slave_forv  sN    0 ${ !7!78  (/XFWX$$_55r   )r   rn   r   r   r   )r   NN)r   r   r   r   r   r+   r   r7   r   strr^   r   r   r   r   r   r   r   r   r   r
   rf   r	   r   r   r   r   r   r   r   r      s   > 00@

 C D !W# !WF	w'		%
J./	0		%
J./	0" $)>T	%6%6 %[%6  $$:;	%6T $)>T	66 %[6  $$:;	6 6r   r   )rL   r   rl   typingr   r   r   r   r   r   r	   redis.asyncio.clientr
   redis.asyncio.connectionr   r   r   r   redis.commandsr   redis.exceptionsr   r   r   r   r   r"   r%   rc   rf   r   r   r   r   <module>r      s       T T T &  1 	/ 		 	>
 >B	#<m 	DN^ DNNj6$ j6r   