Ë
    §Œj¥:  ã                   óþ   — d dl Z d dlZd dlmZ d dlmZ d dlmZ d dlm	Z	m
Z
mZ d dlmZmZmZmZ  G d„ de«      Z G d	„ d
e«      Z G d„ de	«      Z G d„ dee«      Z G d„ d«      Z G d„ de
«      Z G d„ de«      Zy)é    N)ÚOptional)ÚRedis)ÚSentinelCommands)Ú
ConnectionÚConnectionPoolÚSSLConnection)ÚConnectionErrorÚReadOnlyErrorÚResponseErrorÚTimeoutErrorc                   ó   — e Zd Zy)ÚMasterNotFoundErrorN©Ú__name__Ú
__module__Ú__qualname__© ó    úX/var/www/html/Fitness-lenito-AI-main/venv/lib/python3.12/site-packages/redis/sentinel.pyr   r      ó   „ Ør   r   c                   ó   — e Zd Zy)ÚSlaveNotFoundErrorNr   r   r   r   r   r      r   r   r   c                   ób   ‡ — e Zd Zˆ fd„Zd„ Zd„ Zd„ Zd„ Z	 ddddœdee	   d	ee	   fˆ fd
„Z
ˆ xZS )ÚSentinelManagedConnectionc                 óP   •— |j                  d«      | _        t        ‰| �  di |¤Ž y )NÚconnection_poolr   )Úpopr   ÚsuperÚ__init__)ÚselfÚkwargsÚ	__class__s     €r   r   z"SentinelManagedConnection.__init__   s%   ø€ Ø%Ÿz™zÐ*;Ó<ˆÔÜ‰ÑÑ"˜6Ó"r   c                 óð   — | j                   }dt        | «      j                  › dt        | «      j                  › d|j                  › d�}| j
                  r!d| j
                  › d| j                  › �}||z  }|S )NÚ<Ú.ú	(service=z%s)>z,host=z,port=)r   Útyper   r   Úservice_nameÚhostÚport)r    ÚpoolÚsÚ	host_infos       r   Ú__repr__z"SentinelManagedConnection.__repr__   s{   € Ø×#Ñ#ˆà”�T“
×%Ñ%Ð& a¬¨T«
×(;Ñ(;Ð'<Ø˜×)Ñ)Ð*¨$ð0ð 	
ð �9Š9Ø  §¡ ¨6°$·)±)°Ð=ˆIØ�I‘ˆAØˆr   c                 óp   — |\  | _         | _        | j                  | j                  j                  d¬«       y )NF)Úcheck_healthÚretry_socket_connect)r)   r*   Úconnect_check_healthr   Úcheck_connection)r    Úaddresss     r   Ú
connect_toz$SentinelManagedConnection.connect_to(   s5   € Ø&ÑˆŒ	�4”9à×!Ñ!Ø×-Ñ-×>Ñ>Ø!&ð 	"õ 	
r   c                 ó*  — | j                   ry | j                  j                  r*| j                  | j                  j	                  «       «       y | j                  j                  «       D ]  }	 | j                  |«      c S  t        ‚# t        $ r Y Œ)w xY w©N)Ú_sockr   Ú	is_masterr5   Úget_master_addressÚrotate_slavesr	   r   )r    Úslaves     r   Ú_connect_retryz(SentinelManagedConnection._connect_retry0   s   € Ø�:Š:ØØ×Ñ×)Ò)Ø�O‰O˜D×0Ñ0×CÑCÓEÕFà×-Ñ-×;Ñ;Ö=�ðØŸ?™?¨5Ó1Ò1ð >ô
 %Ð$øô 'ò Ùðús   Á,BÂ	BÂBc                 óP   — | j                   j                  | j                  d„ «      S )Nc                  ó   — y r7   r   )Úerrors    r   Ú<lambda>z3SentinelManagedConnection.connect.<locals>.<lambda>>   s   € ÈTr   )ÚretryÚcall_with_retryr=   ©r    s    r   Úconnectz!SentinelManagedConnection.connect=   s    € Ø�z‰z×)Ñ)¨$×*=Ñ*=Ñ?QÓRÐRr   F)Údisconnect_on_errorÚpush_requestrF   rG   c                ó¨   •— 	 t         ‰| �  |||¬«      S # t        $ r3 | j                  j                  r| j                  «        t        d«      ‚‚ w xY w)N)Údisable_decodingrF   rG   z"The previous master is now a slave)r   Úread_responser
   r   r9   Ú
disconnectr	   )r    rI   rF   rG   r"   s       €r   rJ   z'SentinelManagedConnection.read_response@   sc   ø€ ð	Ü‘7Ñ(Ø!1Ø$7Ø)ð )ó ð øô
 ò 		Ø×#Ñ#×-Ò-ð —‘Ô!Ü%Ð&JÓKÐKØð		ús	   ƒ •<A)F)r   r   r   r   r.   r5   r=   rE   r   ÚboolrJ   Ú__classcell__©r"   s   @r   r   r      sU   ø„ ô#ò	ò
ò%òSð
 ðð /4Ø',òð & d™^ð	ð
 ˜t‘n÷ñ r   r   c                   ó   — e Zd Zy)ÚSentinelManagedSSLConnectionNr   r   r   r   rP   rP   Y   r   r   rP   c                   ó$   — e Zd Zd„ Zd„ Zd„ Zd„ Zy)ÚSentinelConnectionPoolProxyc                 ó�   — t        j                  |«      | _        || _        || _        || _        || _        | j                  «        y r7   )ÚweakrefÚrefÚconnection_pool_refr9   r3   r(   Úsentinel_managerÚreset)r    r   r9   r3   r(   rW   s         r   r   z$SentinelConnectionPoolProxy.__init__^   s=   € ô $+§;¡;¨Ó#?ˆÔ Ø"ˆŒØ 0ˆÔØ(ˆÔØ 0ˆÔØ�
‰
�r   c                 ó    — d | _         d | _        y r7   )Úmaster_addressÚslave_rr_counterrD   s    r   rX   z!SentinelConnectionPoolProxy.resetm   s   € Ø"ˆÔØ $ˆÕr   c                 óÜ   — | j                   j                  | j                  «      }| j                  r:| j                  |k7  r+|| _        | j                  «       }|�|j                  d¬«       |S )NF)Úinuse_connections)rW   Údiscover_masterr(   r9   rZ   rV   rK   )r    rZ   r   s      r   r:   z.SentinelConnectionPoolProxy.get_master_addressq   sg   € Ø×.Ñ.×>Ñ>¸t×?PÑ?PÓQˆØ�>Š>˜d×1Ñ1°^ÒCØ"0ˆDÔð #×6Ñ6Ó8ˆOØÐ*Ø×*Ñ*¸UÐ*ÔCØÐr   c              #   óÊ  K  — | j                   j                  | j                  «      }|r| j                  €'t	        j
                  dt        |«      dz
  «      | _        t        t        |«      «      D ]5  }| j                  dz   t        |«      z  | _        || j                     }|–— Œ7 	 | j                  «       –— t        d| j                  ›�«      ‚# t        $ r Y Œ#w xY w­w)Nr   é   zNo slave found for )rW   Údiscover_slavesr(   r[   ÚrandomÚrandintÚlenÚranger:   r   r   )r    ÚslavesÚ_r<   s       r   r;   z)SentinelConnectionPoolProxy.rotate_slaves|   sÓ   è ø€ Ø×&Ñ&×6Ñ6°t×7HÑ7HÓIˆÙØ×$Ñ$Ð,Ü(.¯©°q¼#¸f»+È¹/Ó(J�Ô%Üœ3˜v›;Ö'�Ø)-×)>Ñ)>ÀÑ)BÄcÈ&ÃkÑ(Q�Ô%Ø˜t×4Ñ4Ñ5�Ø“ð (ð
	Ø×)Ñ)Ó+Ò+ô !Ð#6°t×7HÑ7HÐ6KÐ!LÓMÐMøô #ò 	Ùð	üs*   ‚B'C#Â*C Â<C#Ã	C ÃC#ÃC Ã C#N)r   r   r   r   rX   r:   r;   r   r   r   rR   rR   ]   s   „ òò%ò	óNr   rR   c                   óX   ‡ — e Zd ZdZˆ fd„Zd„ Zˆ fd„Zed„ «       Zˆ fd„Z	d„ Z
d„ Zˆ xZS )	ÚSentinelConnectionPoolz¸
    Sentinel backed connection pool.

    If ``check_connection`` flag is set to True, SentinelManagedConnection
    sends a PING command right after establishing the connection.
    c                 ó‚  •— |j                  d|j                  dd«      rt        nt        «      |d<   |j                  dd«      | _        |j                  dd«      | _        t        | | j                  | j
                  ||¬«      | _        t        ‰| �$  d	i |¤Ž | j                  | j                  d<   || _        || _        y )
NÚconnection_classÚsslFr9   Tr3   )r   r9   r3   r(   rW   r   r   )Úgetr   rP   r   r9   r3   rR   Úproxyr   r   Úconnection_kwargsr(   rW   )r    r(   rW   r!   r"   s       €r   r   z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           	      ó    — | j                   rdnd}dt        | «      j                  › dt        | «      j                  › d| j                  › d|› d�	S )NÚmasterr<   r$   r%   r&   Ú(z))>)r9   r'   r   r   r(   )r    Úroles     r   r.   zSentinelConnectionPool.__repr__¬   sR   € ØŸ>š>‰x¨wˆà”�T“
×%Ñ%Ð& a¬¨T«
×(;Ñ(;Ð'<Ø˜×)Ñ)Ð*¨!¨D¨6°ð6ð	
r   c                 óV   •— t         ‰| �  «        | j                  j                  «        y r7   )r   rX   rn   )r    r"   s    €r   rX   zSentinelConnectionPool.reset³   s   ø€ Ü‰‰ŒØ�
‰
×ÑÕr   c                 ó.   — | j                   j                  S r7   )rn   rZ   rD   s    r   rZ   z%SentinelConnectionPool.master_address·   s   € à�z‰z×(Ñ(Ð(r   c                 óÆ   •— | j                    xs3 | j                   xr% | j                  |j                  |j                  fk(  }t	        «       }|xr |j                  |«      S r7   )r9   rZ   r)   r*   r   Úowns_connection)r    Ú
connectionÚcheckÚparentr"   s       €r   rw   z&SentinelConnectionPool.owns_connection»   sZ   ø€ Ø—N‘NÐ"ò 
Ø�N‰NÒX˜t×2Ñ2°z·±È
ÏÉÐ6XÑXð 	ô “ˆØÒ;˜×/Ñ/°
Ó;Ð;r   c                 ó6   — | j                   j                  «       S r7   )rn   r:   rD   s    r   r:   z)SentinelConnectionPool.get_master_addressÂ   s   € Ø�z‰z×,Ñ,Ó.Ð.r   c                 ó6   — | j                   j                  «       S )zRound-robin slave balancer)rn   r;   rD   s    r   r;   z$SentinelConnectionPool.rotate_slavesÅ   s   € à�z‰z×'Ñ'Ó)Ð)r   )r   r   r   Ú__doc__r   r.   rX   ÚpropertyrZ   rw   r:   r;   rM   rN   s   @r   ri   ri   �   s:   ø„ ñô1ò.
ôð ñ)ó ð)ô<ò/ö*r   ri   c                   óZ   — e Zd ZdZ	 	 	 dd„Zd„ Zd„ Zd„ Zd„ Zd„ Z	d	„ Z
eefd
„Zeefd„Zy)ÚSentinelar  
    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           	      ó   — |€5|j                  «       D ��ci c]  \  }}|j                  d«      sŒ||“Œ }}}|| _        |D ��	cg c]  \  }}	t        ||	fi | j                  ¤Ž‘Œ c}	}| _        || _        || _        || _        y c c}}w c c}	}w )NÚsocket_)ÚitemsÚ
startswithÚsentinel_kwargsr   Ú	sentinelsÚmin_other_sentinelsro   Ú_force_master_ip)
r    r†   r‡   r…   Úforce_master_ipro   ÚkÚvÚhostnamer*   s
             r   r   zSentinel.__init__ç   s¨   € ð Ð"à!2×!8Ñ!8Ô!:ôÙ!:™˜˜A¸a¿l¹lÈ9Õ>U��1‘Ð!:ð ñ ð  /ˆÔñ #,ô
á"+‘�˜$ô �(˜DÑ9 D×$8Ñ$8Ó9Ø"+ò
ˆŒð $7ˆÔ Ø!2ˆÔØ /ˆÕùóùó

s   –B°BÁ!B
c                 ól  — t        |j                  dd«      «      }t        |j                  dd«      «      }|r: t        j                  | j                  «      j
                  |i |¤Ž}|r|gS |rdS dS g }| j                  D ]#  }|j                   |j
                  |i |¤Ž«       Œ% |r|S t        |«      S )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_responsesT)rL   r   rb   Úchoicer†   Úexecute_commandÚappendÚall)r    Úargsr!   rŽ   r�   ÚresponseÚ	responsesÚsentinels           r   r‘   zSentinel.execute_commandÿ   sº   € ô �F—J‘J˜v uÓ-Ó.ˆô   §
¡
Ð+=¸uÓ EÓFÐáØD”v—}‘} T§^¡^Ó4×DÑDÀdÐUÈfÑUˆHÙØ �zÐ!á'�tÐ2¨UÐ2àˆ	ØŸœˆHØ×ÑÐ5˜X×5Ñ5°tÐF¸vÑFÕGð 'ñ ØÐä�9‹~Ðr   c                 ó  — g }| j                   D ]6  }|j                  dj                  |j                  j                  «      «       Œ8 dt        | «      j                  › dt        | «      j                  › ddj                  |«      › d�S )Nz{host}:{port}r$   r%   z(sentinels=[Ú,z])>)	r†   r’   Ú
format_mapr   ro   r'   r   r   Újoin)r    Úsentinel_addressesr—   s      r   r.   zSentinel.__repr__  s�   € ØÐØŸœˆHØ×%Ñ%Ø×*Ñ*¨8×+CÑ+C×+UÑ+UÓVõð 'ð
 ”�T“
×%Ñ%Ð& a¬¨T«
×(;Ñ(;Ð'<Ø˜3Ÿ8™8Ð$6Ó7Ð8¸ð=ð	
r   c                 óJ   — |d   r
|d   s|d   ry|d   | j                   k  ryy)Nr9   Úis_sdownÚis_odownFznum-other-sentinelsT)r‡   )r    Ústater(   s      r   Úcheck_master_statezSentinel.check_master_state&  s5   € Ø�[Ò! U¨:Ò%6¸%À
Ò:KØàÐ&Ñ'¨$×*BÑ*BÒBØØr   c                 ó.  — t        «       }t        | j                  «      D ]Ž  \  }}	 |j                  «       }|j                  |«      }|sŒ+| j                  ||«      sŒ>|| j                  d   c| j                  d<   | j                  |<   | j                  �| j                  n|d   }||d   fc S  d}	t        |«      dkD  rddj                  |«      › �}	t        d	|›|	› �«      ‚# t        t
        f$ r }|j                  |› d|›�«       Y d}~Œïd}~ww xY w)
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   Úipr*   Ú z : z, zNo master found for )ÚlistÚ	enumerater†   Úsentinel_mastersr	   r   r’   rm   r¡   rˆ   rd   r›   r   )
r    r(   Úcollected_errorsÚsentinel_nor—   ÚmastersÚer    r£   Ú
error_infos
             r   r^   zSentinel.discover_master.  s2  € ô  ›6ÐÜ%.¨t¯~©~Ö%>Ñ!ˆK˜ðØ"×3Ñ3Ó5�ð —K‘K Ó-ˆEÚ˜×0Ñ0°¸ÕEð Ø—N‘N 1Ñ%ð ?�—‘˜qÑ! 4§>¡>°+Ñ#>ð ×,Ñ,Ð8ð ×)Ò)à˜t™ð ð
 ˜5 ™=Ð(Ò(ð' &?ð* ˆ
ÜÐÓ  1Ò$Ø˜tŸy™yÐ)9Ó:Ð;Ð<ˆJÜ!Ð$8¸Ð8HÈÈÐ"UÓVÐVøô+ $¤\Ð2ò Ø ×'Ñ'¨8¨*°C¸°uÐ(=Ô>Üûðús   §C%Ã%DÃ4DÄDc                 ó`   — g }|D ]&  }|d   s|d   rŒ|j                  |d   |d   f«       Œ( |S )z1Remove slaves that are in an ODOWN or SDOWN staterŸ   rž   r£   r*   )r’   )r    rf   Úslaves_aliver<   s       r   Úfilter_slaveszSentinel.filter_slavesQ  sF   € àˆÛˆEØ�ZÒ  E¨*Ò$5ØØ×Ñ  t¡¨e°F©mÐ <Õ=ð ð Ðr   c                 ó®   — | j                   D ]+  }	 |j                  |«      }| j                  |«      }|sŒ)|c S  g S # t        t        t        f$ r Y ŒFw xY w)z;Returns a list of alive slaves for service ``service_name``)r†   Úsentinel_slavesr	   r   r   r¯   )r    r(   r—   rf   s       r   ra   zSentinel.discover_slavesZ  sa   € àŸœˆHðØ!×1Ñ1°,Ó?�ð ×'Ñ'¨Ó/ˆFÚØ’ð 'ð ˆ	øô $¤]´LÐAò Ùðús   ‘=½AÁAc                 óŠ   — d|d<   t        | j                  «      }|j                  |«       |j                   ||| fi |¤Ž«      S )aý  
        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.
        Tr9   ©Údictro   ÚupdateÚ	from_pool©r    r(   Úredis_classÚconnection_pool_classr!   ro   s         r   Ú
master_forzSentinel.master_forf  sP   € ð> #ˆˆ{ÑÜ  ×!7Ñ!7Ó8ÐØ× Ñ  Ô(Ø×$Ñ$Ù! ,°ÑJÐ8IÑJó
ð 	
r   c                 óŠ   — d|d<   t        | j                  «      }|j                  |«       |j                   ||| fi |¤Ž«      S )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.
        Fr9   r³   r·   s         r   Ú	slave_forzSentinel.slave_forŒ  sP   € ð0 $ˆˆ{ÑÜ  ×!7Ñ!7Ó8ÐØ× Ñ  Ô(Ø×$Ñ$Ù! ,°ÑJÐ8IÑJó
ð 	
r   )r   NN)r   r   r   r}   r   r‘   r.   r¡   r^   r¯   ra   r   ri   rº   r¼   r   r   r   r€   r€   Ê   sR   „ ñð> ØØó0ò0ò8	
òò!WòFò
ð Ø4ó	$
ðR Ø4ô	
r   r€   )rb   rT   Útypingr   Úredis.clientr   Úredis.commandsr   Úredis.connectionr   r   r   Úredis.exceptionsr	   r
   r   r   r   r   r   rP   rR   ri   r€   r   r   r   Ú<module>rÂ      s�   ðÛ Û Ý å Ý +ß FÑ F÷ó ô	˜/ô 	ô	˜ô 	ô> 
ô >ôB	Ð#<¸mô 	÷-Nñ -Nô`:*˜^ô :*ôz_
Ðõ _
r   