ó
    ùÞ jE9  ã                   ó
  • S SK r S SKrS SKJ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 " S S\5      rg)é    N)ÚOptional)Ú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   ó    ÚH/var/www/html/gaurav/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                   óz   ^ • \ 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
\	\
   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%   ø€ Ø%Ÿz™zÐ*;Ó<ˆÔÜ‰ÒÑ"˜6Ó"r   c                 óø   • U R                   nS[        U 5      R                   S[        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   r   Úservice_nameÚhostÚport)r&   ÚpoolÚsÚ	host_infos       r   Ú__repr__Ú"SentinelManagedConnection.__repr__   sy   € Ø×#Ñ#ˆà”�T“
×%Ñ%Ð& a¬¨T«
×(;Ñ(;Ð'<Ø˜×)Ñ)Ð*¨$ð0ð 	
ð �9�9Ø  §¡ ¨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)
r0   r1   r$   Úconnectr"   Úcheck_connectionÚsend_commandr   Úread_responser	   )r&   Úaddressr(   s     €r   Ú
connect_toÚ$SentinelManagedConnection.connect_to$   sc   ø€ Ø&ÑˆŒ	�4”9Ü‰‰ÔØ×Ñ×0×0Ø×Ñ˜fÔ%Ü˜D×.Ñ.Ó0Ó1°VÓ;Ü% 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   € Ø�:�:ØØ×Ñ×)×)Ø�O‰O˜D×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 rB   r   )Úerrors    r   Ú<lambda>Ú3SentinelManagedConnection.connect.<locals>.<lambda>:   s   € ÈTr   )ÚretryÚcall_with_retryrH   ©r&   s    r   r:   Ú!SentinelManagedConnection.connect9   s    € Ø�z‰z×)Ñ)¨$×*=Ñ*=Ñ?QÓRÐRr   F)Údisconnect_on_errorÚpush_requestrS   rT   c                ó®   >•  [         TU ]  UUUS9$ ! [         a8    U R                  R                  (       a  U R                  5         [        S5      ee f = f)N)Údisable_decodingrS   rT   z"The previous master is now a slave)r$   r=   r
   r"   rD   Ú
disconnectr	   )r&   rV   rS   rT   r(   s       €r   r=   Ú'SentinelManagedConnection.read_response<   sc   ø€ ð	Ü‘7Ñ(Ø!1Ø$7Ø)ð )ð ð øô
 ó 		Ø×#Ñ#×-×-ð —‘Ô!Ü%Ð&JÓKÐKØð		ús
   ƒ ’AA)r"   r0   r1   )F)r   r   r   r   r%   r5   r?   rH   r:   r   Úboolr=   r   Ú__classcell__©r(   s   @r   r   r      sU   ø† õ#ò	õ5ò%òSð
 ðð /4Ø',òð & d™^ð	ð
 ˜t‘n÷÷ r   r   c                   ó   • \ rS rSrSrg)ÚSentinelManagedSSLConnectionéU   r   Nr   r   r   r   r]   r]   U   r   r   r]   c                   ó,   • \ rS rSrS rS rS rS rSrg)ÚSentinelConnectionPoolProxyéY   c                 óŠ   • [         R                  " U5      U l        X l        X0l        X@l        XPl        U R                  5         g rB   )ÚweakrefÚrefÚconnection_pool_refrD   r;   r/   Úsentinel_managerÚreset)r&   r"   rD   r;   r/   rf   s         r   r%   Ú$SentinelConnectionPoolProxy.__init__Z   s5   € ô $+§;¢;¨Ó#?ˆÔ Ø"ŒØ 0ÔØ(ÔØ 0ÔØ�
‰
�r   c                 ó    • S U l         S U l        g rB   )Úmaster_addressÚslave_rr_counterrQ   s    r   rg   Ú!SentinelConnectionPoolProxy.reseti   s   € Ø"ˆÔØ $ˆÕr   c                 óâ   • U R                   R                  U R                  5      nU R                  (       a8  U R                  U:w  a(  Xl        U R                  5       nUb  UR                  SS9  U$ )NF)Úinuse_connections)rf   Údiscover_masterr/   rD   rj   re   rW   )r&   rj   r"   s      r   rE   Ú.SentinelConnectionPoolProxy.get_master_addressm   se   € Ø×.Ñ.×>Ñ>¸t×?PÑ?PÓQˆØ�>�>˜d×1Ñ1°^ÓCØ"0Ôð #×6Ñ6Ó8ˆOØÑ*Ø×*Ñ*¸UÐ*ÑCØÐ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)Nr   é   zNo slave found for )rf   Údiscover_slavesr/   rk   ÚrandomÚrandintÚlenÚrangerE   r   r   )r&   ÚslavesÚ_rG   s       r   rF   Ú)SentinelConnectionPoolProxy.rotate_slavesx   sÐ   é € Ø×&Ñ&×6Ñ6°t×7HÑ7HÓIˆÞØ×$Ñ$Ñ,Ü(.¯ª°q¼#¸f»+È¹/Ó(J�Ô%Üœ3˜v›;Ö'�Ø)-×)>Ñ)>ÀÑ)BÄcÈ&ÃkÑ(Q�Ô%Ø×4Ñ4Ñ5�Ø”ñ (ð
	Ø×)Ñ)Ó+Ò+ô !Ð#6°t×7HÑ7HÑ6KÐ!LÓMÐMøô #ó 	Ùð	üs*   ‚B/C-Â2C ÃC-Ã
C*Ã'C-Ã)C*Ã*C-)r;   re   rD   rj   rf   r/   rk   N)	r   r   r   r   r%   rg   rE   rF   r   r   r   r   r`   r`   Y   s   † òò%ò	õNr   r`   c                   óf   ^ • \ rS rSrSrU 4S jrS rU 4S jr\S 5       r	U 4S jr
S rS	 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                 ó„  >• 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        [        U U R                  U R
                  UUS9U l        [        TU ]$  " S	0 UD6  U R                  U R                  S'   Xl        X l        g )
NÚconnection_classÚsslFrD   Tr;   )r"   rD   r;   r/   rf   r"   r   )Úgetr#   r]   r   rD   r;   r`   Úproxyr$   r%   Úconnection_kwargsr/   rf   )r&   r/   rf   r'   r(   s       €r   r%   ÚSentinelConnectionPool.__init__‘   sµ   ø€ Ø%+§Z¡ZØð —:‘:˜e U×+Ñ+õ -ä.ó&
ˆÐ!Ñ"ð  Ÿ™ K°Ó6ˆŒØ &§
¡
Ð+=¸uÓ EˆÔÜ0Ø Ø—n‘nØ!×2Ñ2Ø%Ø-ñ
ˆŒ
ô 	‰ÒÑ"˜6Ò"Ø48·J±Jˆ×ÑÐ0Ñ1Ø(ÔØ 0Õr   c           	      óª   • U R                   (       a  SOSnS[        U 5      R                   S[        U 5      R                   SU R                   SU S3	$ )NÚmasterrG   r+   r,   r-   Ú(z))>)rD   r.   r   r   r/   )r&   Úroles     r   r5   ÚSentinelConnectionPool.__repr__¨   sR   € ØŸ>Ÿ>‰x¨wˆà”�T“
×%Ñ%Ð& a¬¨T«
×(;Ñ(;Ð'<Ø˜×)Ñ)Ð*¨!¨D¨6°ð6ð	
r   c                 óV   >• [         TU ]  5         U R                  R                  5         g rB   )r$   rg   r‚   )r&   r(   s    €r   rg   ÚSentinelConnectionPool.reset¯   s   ø€ Ü‰‰ŒØ�
‰
×ÑÕr   c                 ó.   • U R                   R                  $ rB   )r‚   rj   rQ   s    r   rj   Ú%SentinelConnectionPool.master_address³   s   € à�z‰z×(Ñ(Ð(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      $ rB   )rD   rj   r0   r1   r$   Úowns_connection)r&   Ú
connectionÚcheckÚparentr(   s       €r   r�   Ú&SentinelConnectionPool.owns_connection·   sZ   ø€ Ø—N‘NÔ"÷ 
Ø�N‰N×X˜t×2Ñ2°z·±È
ÏÉÐ6XÑXð 	ô “ˆØ×;˜×/Ñ/°
Ó;Ð;r   c                 ó6   • U R                   R                  5       $ rB   )r‚   rE   rQ   s    r   rE   Ú)SentinelConnectionPool.get_master_address¾   s   € Ø�z‰z×,Ñ,Ó.Ð.r   c                 ó6   • U R                   R                  5       $ )zRound-robin slave balancer)r‚   rF   rQ   s    r   rF   Ú$SentinelConnectionPool.rotate_slavesÁ   s   € à�z‰z×'Ñ'Ó)Ð)r   )r;   rD   r‚   rf   r/   )r   r   r   r   Ú__doc__r%   r5   rg   Úpropertyrj   r�   rE   rF   r   rZ   r[   s   @r   r|   r|   ‰   s?   ø† ñõ1ò.
õð ñ)ó ð)õ<ò/÷*ð *r   r|   c                   óh   • \ 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  pgUR                  S5      (       d  M  Xg_M!     nnnX0l        U VV	s/ sH  u  p‰[        X‰40 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_)ÚitemsÚ
startswithÚsentinel_kwargsr   Ú	sentinelsÚmin_other_sentinelsrƒ   Ú_force_master_ip)
r&   r¢   r£   r¡   Úforce_master_iprƒ   ÚkÚvÚhostnamer1   s
             r   r%   ÚSentinel.__init__ã   sš   € ð Ñ"à!2×!8Ñ!8Ô!:ôÙ!:™˜¸a¿l¹lÈ9×>U“�’Ñ!:ð ñ ð  /Ôñ #,ô
á"+‘�ô �(Ñ9 D×$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)rY   r�   Úkeysr#   rt   Úchoicer¢   Úexecute_command)r&   Úargsr'   r«   Úsentinels        r   r®   ÚSentinel.execute_commandû   s�   € ô �F—J‘J˜v uÓ-Ó.ˆØ�V—[‘[“]Ó"Ø�J‰J�vÔæÜ�MŠM˜$Ÿ.™.Ó)×9Ò9¸4ÐJÀ6ÒJð ð !ŸNœN�Ø×(Ò(¨$Ð9°&Ô9ñ +àr   c                 ó  • / nU R                    H7  nUR                  SR                  UR                  R                  5      5        M9     S[        U 5      R                   S[        U 5      R                   SSR                  U5       S3$ )Nz{host}:{port}r+   r,   z(sentinels=[Ú,z])>)	r¢   ÚappendÚ
format_mapr"   rƒ   r.   r   r   Újoin)r&   Úsentinel_addressesr°   s      r   r5   ÚSentinel.__repr__  s�   € ØÐØŸœˆHØ×%Ñ%Ø×*Ñ*¨8×+CÑ+C×+UÑ+UÓVöñ 'ð
 ”�T“
×%Ñ%Ð& a¬¨T«
×(;Ñ(;Ð'<Ø˜3Ÿ8™8Ð$6Ó7Ð8¸ð=ð	
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&   Ústater/   s      r   Úcheck_master_stateÚSentinel.check_master_state  s5   € Ø�[×! U¨:×%6¸%À
×:KØàÐ&Ñ'¨$×*BÑ*BÓBØØr   c                 óN  • [        5       n[        U R                  5       H˜  u  p4 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 R                  b  U R                  OUS   nX‡S   4s  $    Sn	[        U5      S:”  a  SSR                  U5       3n	[        S	U< U	 35      e! [        [
        4 a"  nUR                  U SU< 35         SnAMÿ  SnAf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.
z - Nr   Úipr1   Ú z : z, zNo master found for )ÚlistÚ	enumerater¢   Úsentinel_mastersr	   r   r´   r�   r½   r¤   rv   r¶   r   )
r&   r/   Úcollected_errorsÚsentinel_nor°   ÚmastersÚer¼   rÀ   Ú
error_infos
             r   ro   ÚSentinel.discover_master  s1  € ô  ›6ÐÜ%.¨t¯~©~Ö%>Ñ!ˆKðØ"×3Ñ3Ó5�ð —K‘K Ó-ˆEßˆu˜×0Ñ0°×EÓEð Ø—N‘N 1Ñ%ð ?�—‘˜qÑ! 4§>¡>°+Ñ#>ð ×,Ñ,Ñ8ð ×)Ò)à˜t™ð ð
  ™=Ð(Ò(ñ' &?ð* ˆ
ÜÐÓ  1Ó$Ø˜tŸy™yÐ)9Ó:Ð;Ð<ˆJÜ!Ð$8¸Ñ8HÈÈÐ"UÓVÐVøô+ $¤\Ð2ó Ø ×'Ñ'¨8¨*°C¸±uÐ(=Ô>Ýûðús   ¦C2Ã2D$ÄDÄD$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À   r1   )r´   )r&   rx   Úslaves_aliverG   s       r   Úfilter_slavesÚSentinel.filter_slavesB  sF   € àˆÛˆEØ�Z×  E¨*×$5ÙØ×Ñ  t¡¨e°F©mÐ <Ö=ñ ð Ð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°   rx   s       r   rs   ÚSentinel.discover_slavesK  sc   € àŸœˆHðØ!×1Ñ1°,Ó?�ð ×'Ñ'¨Ó/ˆFßˆvØ’ñ 'ð ˆ	øô $¤]´LÐAó Úðús   ‘AÁAÁAc                 óˆ   • SUS'   [        U R                  5      nUR                  U5        UR                  U" X40 UD6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.
TrD   ©Údictrƒ   ÚupdateÚ	from_pool©r&   r/   Úredis_classÚconnection_pool_classr'   rƒ   s         r   Ú
master_forÚSentinel.master_forW  sN   € ð: #ˆˆ{ÑÜ  ×!7Ñ!7Ó8ÐØ× Ñ  Ô(Ø×$Ñ$Ù! ,ÑJÐ8IÑJó
ð 	
r   c                 óˆ   • SUS'   [        U R                  5      nUR                  U5        UR                  U" X40 UD6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_for{  sN   € ð0 $ˆˆ{ÑÜ  ×!7Ñ!7Ó8ÐØ× Ñ  Ô(Ø×$Ñ$Ù! ,ÑJÐ8IÑJó
ð 	
r   )r¤   rƒ   r£   r¡   r¢   )r   NN)r   r   r   r   r˜   r%   r®   r5   r½   ro   rÍ   rs   r   r|   rÚ   rÝ   r   r   r   r   r›   r›   Æ   sR   † ñð> ØØô0ò0ò"	
òò!WòFò
ð Ø4ô	"
ðN Ø4÷	
r   r›   )rt   rc   Útypingr   Úredis.clientr   Úredis.commandsr   Úredis.connectionr   r   r   Úredis.exceptionsr	   r
   r   r   Úredis.utilsr   r   r   r   r]   r`   r|   r›   r   r   r   Ú<module>rå      s€   ðÛ Û Ý å Ý +ß FÑ Fß XÓ XÝ $ô	˜/ô 	ô	˜ô 	ô> 
ô >ôB	Ð#<¸mô 	÷-Nñ -Nô`:*˜^ô :*ôzR
Ðõ R
r   