
    RiR1                         S SK r S SKrS SKJr  S SKJr  S SKJrJr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)Redis)SentinelCommands)
ConnectionConnectionPoolSSLConnection)ConnectionErrorReadOnlyErrorResponseErrorTimeoutError)str_if_bytesc                       \ rS rSrSrg)MasterNotFoundError    N__name__
__module____qualname____firstlineno____static_attributes__r       `/var/www/html/backend/Backoffice_Marketplace/venv/lib/python3.13/site-packages/redis/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                   V   ^  \ rS rSrU 4S jrS rU 4S jrS rS rS	U 4S 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                     U R                   n[        U 5      R                   SUR                   S3nU R                  (       a   SU R                   SU R
                   3nX#-  nU$ )N	<service=z%s>z,host=z,port=)r!   typer   service_namehostport)r%   pools	host_infos       r   __repr__"SentinelManagedConnection.__repr__   s^    ##Dz""#9T->->,?sC99 6$))=IAr   c                    > Uu  U l         U l        [        TU ]  5         U R                  R
                  (       a:  U R                  S5        [        U R                  5       5      S:w  a  [        S5      eg g )NPINGPONGzPING failed)
r-   r.   r#   connectr!   check_connectionsend_commandr   read_responser   )r%   addressr'   s     r   
connect_to$SentinelManagedConnection.connect_to    sc    &	4900f%D..01V;%m44 < 1r   c                 D   U R                   (       a  g U R                  R                  (       a*  U R                  U R                  R	                  5       5        g U R                  R                  5        H  n U R                  U5      s  $    [        e! [         a     M,  f = fN)_sockr!   	is_masterr<   get_master_addressrotate_slavesr   r   )r%   slaves     r   _connect_retry(SentinelManagedConnection._connect_retry(   s    ::))OOD00CCEF--;;=??511 >
 %$ ' s   6B
BBc                 P    U R                   R                  U R                  S 5      $ )Nc                     g r?   r   )errors    r   <lambda>3SentinelManagedConnection.connect.<locals>.<lambda>6   s    Tr   )retrycall_with_retryrE   )r%   s    r   r7   !SentinelManagedConnection.connect5   s     zz))$*=*=?QRRr   c                    >  [         TU ]  US9$ ! [         a8    U R                  R                  (       a  U R                  5         [        S5      ee f = f)N)disable_decodingz"The previous master is now a slave)r#   r:   r	   r!   rA   
disconnectr   )r%   rP   r'   s     r   r:   'SentinelManagedConnection.read_response8   sU    	7(:J(KK 		##-- !%&JKK		s
    AA)r!   r-   r.   )F)r   r   r   r   r$   r2   r<   rE   r7   r:   r   __classcell__r'   s   @r   r   r      s'    #5%S r   r   c                       \ rS rSrSrg)SentinelManagedSSLConnectionG   r   Nr   r   r   r   rV   rV   G   r   r   rV   c                   V   ^  \ rS rSrSrU 4S jrS rU 4S jrU 4S jrS r	S r
S	rU =r$ )
SentinelConnectionPoolK   z
Sentinel backed connection pool.

If ``check_connection`` flag is set to True, SentinelManagedConnection
sends a PING command right after establishing the connection.
c                 L  > 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        g )	Nconnection_classsslFrA   Tr8   r!   r   )getr"   rV   r   rA   r8   r#   r$   weakrefproxyconnection_kwargsr,   sentinel_manager)r%   r,   rb   r&   r'   s       r   r$   SentinelConnectionPool.__init__S   s    %+ZZzz%'' )*	&
!"  K6 &

+=u E"6"4;MM$4G01( 0r   c                 |    U R                   (       a  SOSn[        U 5      R                   SU R                   SU S3$ )NmasterrD   r*   ())rA   r+   r   r,   )r%   roles     r   r2   SentinelConnectionPool.__repr__a   s:    >>xwt*%%&i0A0A/B!D6KKr   c                 >   > [         TU ]  5         S U l        S U l        g r?   )r#   resetmaster_addressslave_rr_counter)r%   r'   s    r   rk   SentinelConnectionPool.resete   s    " $r   c                    > U R                   (       + =(       d8    U R                   =(       a%    U R                  UR                  UR                  4:H  n[	        5       nU=(       a    UR                  U5      $ r?   )rA   rl   r-   r.   r#   owns_connection)r%   
connectioncheckparentr'   s       r   rp   &SentinelConnectionPool.owns_connectionj   sZ    NN" 
NNXt22z
6XX 	 ;//
;;r   c                     U R                   R                  U R                  5      nU R                  (       a%  U R                  U:w  a  Xl        U R                  SS9  U$ )NF)inuse_connections)rb   discover_masterr,   rA   rl   rQ   )r%   rl   s     r   rB   )SentinelConnectionPool.get_master_addressq   sO    ..>>t?P?PQ>>""n4&4# %8r   c              #     #    U R                   R                  U R                  5      nU(       a  U R                  c(  [        R
                  " S[        U5      S-
  5      U l        [        [        U5      5       H5  nU R                  S-   [        U5      -  U l        XR                     nUv   M7      U R                  5       v   [        SU R                  < 35      e! [         a     N%f = f7f)zRound-robin slave balancerr      zNo slave found for )rb   discover_slavesr,   rm   randomrandintlenrangerB   r   r   )r%   slaves_rD   s       r   rC   $SentinelConnectionPool.rotate_slaves{   s     &&66t7H7HI$$,(.q#f+/(J%3v;')-)>)>)Bc&k(Q%445 (
	))++ !#6t7H7H6K!LMM # 		s*   B/C-2C C-
C*'C-)C**C-)r8   rA   rl   rb   r,   rm   )r   r   r   r   __doc__r$   r2   rk   rp   rB   rC   r   rS   rT   s   @r   rY   rY   K   s.    1L%
<N Nr   rY   c                   f    \ rS rSrSr  SS jrS rS rS rS r	S	 r
S
 r\\4S jr\\4S 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)
>>> 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           	         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[        Xx40 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_)items
startswithsentinel_kwargsr   	sentinelsmin_other_sentinelsra   )	r%   r   r   r   ra   kvhostnamer.   s	            r   r$   Sentinel.__init__   s     "!2!8!8!:!:all9>U!:    / #,
"+ (9D$8$89"+
 $7 !2

s   BB"B	c                 >   [        UR                  SS5      5      nSUR                  5       ;   a  UR                  S5        U(       a1  [        R
                  " U R                  5      R                  " U0 UD6  gU R                   H  nUR                  " U0 UD6  M     g)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)boolr^   keysr"   r|   choicer   execute_command)r%   argsr&   r   sentinels        r   r   Sentinel.execute_command   s     FJJvu-.V[[]"JJvMM$..)994J6J  !NN(($9&9 +r   c                     / nU R                    H7  nUR                  SR                  UR                  R                  5      5        M9     [        U 5      R                   SSR                  U5       S3$ )Nz{host}:{port}z<sentinels=[,z]>)r   append
format_mapr!   ra   r+   r   join)r%   sentinel_addressesr   s      r   r2   Sentinel.__repr__   sj    H%%**8+C+C+U+UV ' t*%%&l388<N3O2PPRSSr   c                 j    US   (       a  US   (       d
  US   (       a  gUS   U R                   :  a  gg)NrA   is_sdownis_odownFznum-other-sentinelsT)r   )r%   stater,   s      r   check_master_stateSentinel.check_master_state   s5    [!U:%6%
:K&'$*B*BBr   c                 |   [        U R                  5       H~  u  p# UR                  5       nUR                  U5      nU(       d  M0  U R                  XQ5      (       d  MH  UU R                  S   sU R                  S'   U R                  U'   US   US   4s  $    [        SU< 35      e! [        [        4 a     M  f = 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.
r   ipr.   zNo master found for )	enumerater   sentinel_mastersr   r   r^   r   r   )r%   r,   sentinel_nor   mastersr   s         r   rw   Sentinel.discover_master   s     &/t~~%>!K"335 KK-Eu00EE NN1% ?q!4>>+#> T{E&M11 &? "$88H"IJJ $\2 s   B''B;:B;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   r.   )r   )r%   r   slaves_aliverD   s       r   filter_slavesSentinel.filter_slaves   sF    EZ E*$5teFm <=  r   c                     U R                    H1  n UR                  U5      nU R                  U5      nU(       d  M/  Us  $    / $ ! [        [        [        4 a     MO  f = f)z;Returns a list of alive slaves for service ``service_name``)r   sentinel_slavesr   r
   r   r   )r%   r,   r   r   s       r   r{   Sentinel.discover_slaves  sc    H!11,? ''/Fv ' 	 $]LA s   AAAc                 r    SUS'   [        U R                  5      nUR                  U5        U" U" X40 UD6S9$ )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.
TrA   r!   dictra   updater%   r,   redis_classconnection_pool_classr&   ra   s         r   
master_forSentinel.master_for  sM    : #{ !7!78  (1&7
 	
r   c                 r    SUS'   [        U R                  5      nUR                  U5        U" U" X40 UD6S9$ )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.
FrA   r   r   r   s         r   	slave_forSentinel.slave_for3  sM    0 ${ !7!78  (1&7
 	
r   )ra   r   r   r   )r   N)r   r   r   r   r   r$   r   r2   r   rw   r   r{   r   rY   r   r   r   r   r   r   r   r      sO    > 	3,"TK.
 4	$
R 4	
r   r   )r|   r_   redis.clientr   redis.commandsr   redis.connectionr   r   r   redis.exceptionsr   r	   r
   r   redis.utilsr   r   r   r   rV   rY   r   r   r   r   <module>r      sr       + F F X X $	/ 		 	1
 1h	#<m 	?N^ ?NDE
 E
r   