+
     hE9  c                   s   ^ RI t ^ RIt^ RIHt ^ RIHt ^ RIHt ^ RIH	t	H
t
Ht ^ RIHtHtHtHt ^ RIHt  ! R R	]4      t ! R
 R]4      t ! R R]	4      t ! R R]]4      t ! R R4      t ! R R]
4      t ! R R]4      tR# )    N)Optional)Redis)SentinelCommands)
ConnectionConnectionPoolSSLConnection)ConnectionErrorReadOnlyErrorResponseErrorTimeoutError)str_if_bytesc                   s    ] tR t^tRtR# )MasterNotFoundError N__name__
__module____qualname____firstlineno____static_attributes__r       3/usr/lib/python3.14/site-packages/redis/sentinel.pyr   r          r   r   c                   s    ] tR t^tRtR# )SlaveNotFoundErrorr   Nr   r   r   r   r   r      r   r   r   c                   sx   a a ] tR t^t oV 3R ltR tV 3R ltR tR tRRRRR/V3R	 lV 3R
 llllt	Rt
VtV ;t# )SentinelManagedConnectionc                sT   < VP                  R 4      V n        \        SV `  ! R/ VB  R# )connection_poolNr   )popr   super__init__)selfkwargs	__class__s   &,r   r   Z"SentinelManagedConnection.__init__   s%    %zz*;<"6"r   c                s   V P                   pR \        V 4      P                   R\        V 4      P                   RVP                   R2pV P
                  '       d%   RV P
                   RV P                   2pW#,          pV# )<.	(service=z%s)>z,host=z,port=)r   typer   r   service_namehostport)r   ZpoolZsZ	host_info   &   r   __repr__Z"SentinelManagedConnection.__repr__   s{    ##T
%%&aT
(;(;'<))*$0 	
 999 6$))=IAr   c                s   < Vw  V n         V n        \        SV `  4        V P                  P
                  '       d=   V P                  R 4       \        V P                  4       4      R8w  d   \        R4      hR# R# )ZPINGZPONGzPING failedN)
r%   r&   r   connectr   check_connectionZsend_commandr   read_responser   )r   Zaddressr   s   &&r   
connect_toZ$SentinelManagedConnection.connect_to$   sf    &	49000f%D..01V;%m44 < 1r   c                sN   V P                   '       d   R # V P                  P                  '       d,   V P                  V P                  P	                  4       4       R # V P                  P                  4        F  p V P                  V4      u # 	  \        h  \         d     K-  i ; iN)Z_sockr   	is_masterr,   get_master_addressrotate_slavesr   r   )r   slave   & r   _connect_retryZ(SentinelManagedConnection._connect_retry,   s    :::)))OOD00CCEF--;;=??511 >
 %$ ' s   :BB$#B$c                sP    V P                   P                  V P                  R  4      # )c                 s    R # r-   r   )Zerror   &r   Z<lambda>Z3SentinelManagedConnection.connect.<locals>.<lambda>:   s    Tr   )ZretryZcall_with_retryr3   r   r4   r   r)   Z!SentinelManagedConnection.connect9   s     zz))$*=*=?QRRr   Fdisconnect_on_errorpush_requestc                sF   < V ^8  d   QhRS[ S[,          RS[ S[,          /# )i   r6   r7   )r   bool)Zformat__classdict__s   "r   Z__annotate__Z&SentinelManagedConnection.__annotate__<   s)       &d^	
 tnr   c               s   <  \         SV `  VVVR 7      #   \         d:    T P                  P                  '       d   T P                  4        \        R4      hh i ; i))disable_decodingr6   r7   z"The previous master is now a slave)r   r+   r   r   r.   
disconnectr   )r   r:   r6   r7   r   s   &&$$r   r+   Z'SentinelManagedConnection.read_response<   sf    	7(!1$7) )  
  		##--- !%&JKK		s    &AA)r   r%   r&   )F)r   r   r   r   r   r(   r,   r3   r)   r+   r   __classdictcell____classcell__r   r9      @@r   r   r      sB     #	5%S /4	
 (-  r   r   c                   s    ] tR t^UtRtR# )SentinelManagedSSLConnectionr   Nr   r   r   r   r@   r@   U   r   r   r@   c                   s8   a  ] tR t^Yt o R tR tR tR tRtV t	R# )SentinelConnectionPoolProxyc                s    \         P                  ! V4      V n        W n        W0n        W@n        WPn        V P                  4        R # r-   )weakrefZrefconnection_pool_refr.   r*   r$   sentinel_managerreset)r   r   r.   r*   r$   rD   s   &&&&&&r   r   Z$SentinelConnectionPoolProxy.__init__Z   s5     $+;;#? " 0( 0

r   c                s"    R V n         R V n        R # r-   )master_addressslave_rr_counterr5   r4   r   rE   Z!SentinelConnectionPoolProxy.reseti   s    " $r   c                s    V P                   P                  V P                  4      pV P                  '       d>   V P                  V8w  d-   Wn        V P                  4       pVe   VP                  RR7       V# )NF)Zinuse_connections)rD   discover_masterr$   r.   rF   rC   r;   )r   rF   r      &  r   r/   Z.SentinelConnectionPoolProxy.get_master_addressm   sg    ..>>t?P?PQ>>>d11^C"0 #668O***U*Cr   c              #  s  "   V P                   P                  V P                  4      pV'       d   V P                  f-   \        P
                  ! ^ \        V4      ^,
          4      V n        \        \        V4      4       FA  pV P                  ^,           \        V4      ,          V n        WP                  ,          pVx  KC  	   V P                  4       x  \        RV P                  : 24      h  \         d     L&i ; i5i)NzNo slave found for )rD   discover_slavesr$   rG   randomZrandintlenZranger/   r   r   )r   slavesZ_r1   r'   r   r0   Z)SentinelConnectionPoolProxy.rotate_slavesx   s     &&66t7H7HI$$,(.q#f+/(J%3v;')-)>)>)Bc&k(Q%445 (
	))++ !#6t7H7H6K!LMM # 		s*   CD C/ D /C=:D <C==D )r*   rC   r.   rF   rD   r$   rG   N)
r   r   r   r   r   rE   r/   r0   r   r<   r9      @r   rA   rA   Y   s      %	N Nr   rA   c                   sp   a a ] tR t^t oRtV 3R ltR tV 3R lt]R 4       t	V 3R lt
R tR tR	tVtV ;t# )
SentinelConnectionPoolz
Sentinel backed connection pool.

If ``check_connection`` flag is set to True, SentinelManagedConnection
sends a PING command right after establishing the connection.
c                s  < TP                  R VP                  RR4      '       d   \        M\        4      VR &   VP                  RR4      V n        VP                  RR4      V n        \        V V P                  V P
                  VVR7      V n        \        SV `$  ! R	/ VB  V P                  V P                  R&   Wn        W n        R# )
Zconnection_classZsslFr.   Tr*   )r   r.   r*   r$   rD   r   Nr   )getr   r@   r   r.   r*   rA   proxyr   r   connection_kwargsr$   rD   )r   r$   rD   r   r   s   &&&,r   r   ZSentinelConnectionPool.__init__   s    %+ZZ ::eU++ -.&
!"  K6 &

+=u E0 nn!22%-

 	"6"48JJ01( 0r   c           	     s    V P                   '       d   R MRpR\        V 4      P                   R\        V 4      P                   RV P                   RV R2	# )Zmasterr1   r    r!   r"   Z(z))>)r.   r#   r   r   r$   )r   Zroler2   r   r(   ZSentinelConnectionPool.__repr__   sT    >>>xwT
%%&aT
(;(;'<))*!D66	
r   c                sX   < \         SV `  4        V P                  P                  4        R # r-   )r   rE   rR   )r   r   s   &r   rE   ZSentinelConnectionPool.reset   s    

r   c                s.    V P                   P                  # r-   )rR   rF   r5   r4   r   rF   Z%SentinelConnectionPool.master_address   s    zz(((r   c                s   < V P                   '       * ;'       g:    V P                   ;'       d&    V P                  VP                  VP                  38H  p\	        4       pT;'       d    VP                  V4      # r-   )r.   rF   r%   r&   r   owns_connection)r   Z
connectionZcheckZparentr   s   &&  r   rT   Z&SentinelConnectionPool.owns_connection   se    NN" 
 
NNXXt22z
6XX 	 ;;//
;;r   c                6    V P                   P                  4       # r-   )rR   r/   r5   r4   r   r/   Z)SentinelConnectionPool.get_master_address   s    zz,,..r   c                rU   )zRound-robin slave balancer)rR   r0   r5   r4   r   r0   Z$SentinelConnectionPool.rotate_slaves   s    zz''))r   )r*   r.   rR   rD   r$   )r   r   r   r   __doc__r   r(   rE   ZpropertyrF   rT   r/   r0   r   r<   r=   r>   r?   r   rP   rP      sA     1.
 ) )</* *r   rP   c                   sn   a  ] tR t^t o RtRR ltR tR tR tR t	R t
R	 t]]3R
 lt]]3R ltRtV tR# )Sentinela  
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)
>>> master.set('foo', 'bar')
>>> slave = sentinel.slave_for('mymaster', socket_timeout=0.1)
>>> 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           	     s,   Vf=   VP                  4        UUu/ uF   w  rgVP                  R4      '       g   K  WgbK"  	  pppW0n        V UU	u. uF  w  r\        W3/ V P                  B NK  	  up	pV n        W n        WPn        W@n        R # u uppi u up	pi )NZsocket_)ZitemsZ
startswithsentinel_kwargsr   	sentinelsmin_other_sentinelsrS   _force_master_ip)
r   rY   rZ   rX   Zforce_master_iprS   ZkZvZhostnamer&   s
   &&&&&,    r   r   ZSentinel.__init__   s     "!2!8!8!:!:all9>U!:    / #,
"+ (9D$8$89"+
 $7 !2 /

s   B
B
!Bc                sF   \        VP                  RR4      4      pRVP                  4       9   d   VP                  R4       V'       d3   \        P
                  ! V P                  4      P                  ! V/ VB  R# V P                   F  pVP                  ! V/ VB  K  	  R# )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.
onceFT)r8   rQ   Zkeysr   rK   ZchoicerY   execute_command)r   Zargsr   r\   sentinels   &*,  r   r]   ZSentinel.execute_command   s     FJJvu-.V[[]"JJvMM$..)994J6J  !NN(($9&9 +r   c                s   . pV P                    F7  pVP                  R P                  VP                  P                  4      4       K9  	  R\        V 4      P                   R\        V 4      P                   RRP                  V4       R2# )z{host}:{port}r    r!   z(sentinels=[Z,z])>)	rY   appendZ
format_mapr   rS   r#   r   r   join)r   Zsentinel_addressesr^   rI   r   r(   ZSentinel.__repr__  s    H%%**8+C+C+U+UV '
 T
%%&aT
(;(;'<388$678=	
r   c                s    VR ,          '       d   VR,          '       g   VR,          '       d   R# VR,          V P                   8  d   R# R# )r.   is_sdownis_odownFznum-other-sentinelsT)rZ   )r   stater$   s   &&&r   check_master_stateZSentinel.check_master_state  s>    [!!U:%6%6%
:K:K&'$*B*BBr   c                sr   \        4       p\        V P                  4       F  w  r4 VP                  4       pTP                  T4      pT'       g   K1  T P                  Yq4      '       g   KJ  TT P                  ^ ,          uT P                  ^ &   T P                  T&   T P                  e   T P                  MTR,          pYR,          3u # 	  Rp	\        V4      ^ 8  d   RRP                  V4       2p	\        RV: V	 24      h  \        \
        3 d$   pTP                  T RT: 24        Rp?EK  Rp?ii ; i)	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.
z - Nipr&   Z z : z, zNo master found for )ZlistZ	enumeraterY   Zsentinel_mastersr   r
   r_   rQ   rd   r[   rL   r`   r   )
r   r$   Zcollected_errorsZsentinel_nor^   ZmastersZerc   re   Z
error_infos
   &&        r   rH   ZSentinel.discover_master  s1     6%.t~~%>!K"335 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(=>s   DD6D11D6c                s    . pV FD  pVR,          '       g   VR,          '       d   K#  VP                  VR,          VR,          34       KF  	  V# )z1Remove slaves that are in an ODOWN or SDOWN staterb   ra   re   r&   )r_   )r   rM   Zslaves_aliver1      &&  r   filter_slavesZSentinel.filter_slavesB  sL    EZ  E*$5$5teFm <=  r   c                s    V P                    F2  p VP                  V4      pT P                  T4      pT'       g   K0  Tu # 	  . #   \        \        \        3 d     KQ  i ; i)z;Returns a list of alive slaves for service ``service_name``)rY   Zsentinel_slavesr   r	   r
   rg   )r   r$   r^   rM   rf   r   rJ   ZSentinel.discover_slavesK  sc    H!11,? ''/Fv ' 	 $]LA s   AAAc                    RVR&   \        V P                  4      pVP                  V4       VP                  V! W3/ VB 4      # )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.
Tr.   ZdictrS   ZupdateZ	from_poolr   r$   Zredis_classZconnection_pool_classr   rS      &&&&, r   
master_forZSentinel.master_forW  sN    : #{ !7!78  ($$!,J8IJ
 	
r   c                rh   )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.
Fr.   ri   rj   rk   r   	slave_forZSentinel.slave_for{  sN    0 ${ !7!78  ($$!,J8IJ
 	
r   )r[   rS   rZ   rX   rY   )r    NN)r   r   r   r   rV   r   r]   r(   rd   rH   rg   rJ   r   rP   rl   rm   r   r<   rN   rO   r   rW   rW      sO     800"	
!WF
 4	"
N 4	
 
r   rW   )rK   rB   Ztypingr   Zredis.clientr   Zredis.commandsr   Zredis.connectionr   r   r   Zredis.exceptionsr   r   r	   r
   Zredis.utilsr   r   r   r   r@   rA   rP   rW   r   r   r   <module>rn      s        + F F X X $	/ 		 	>
 >B	#<m 	-N -N`:*^ :*zR
 R
r   