HEX
Server: LiteSpeed
System: Linux us-phx-web1284.main-hosting.eu 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: u300739242 (300739242)
PHP: 8.2.30
Disabled: system, shell_exec, passthru, mysql_list_dbs, ini_alter, dl, symlink, link, chgrp, leak, popen, apache_child_terminate, virtual, mb_send_mail
Upload Files
File: //opt/alt/python311/lib/python3.11/site-packages/redis/__pycache__/sentinel.cpython-311.pyc
�

$�;f�1���ddlZddlZddlmZddlmZddlmZmZm	Z	ddl
mZmZm
Z
mZddlmZGd�de��ZGd	�d
e��ZGd�de��ZGd
�dee	��ZGd�de��ZGd�de��ZdS)�N)�Redis)�SentinelCommands)�
Connection�ConnectionPool�
SSLConnection)�ConnectionError�
ReadOnlyError�
ResponseError�TimeoutError)�str_if_bytesc��eZdZdS)�MasterNotFoundErrorN��__name__�
__module__�__qualname__���A/opt/alt/python311/lib/python3.11/site-packages/redis/sentinel.pyrr��������Drrc��eZdZdS)�SlaveNotFoundErrorNrrrrrrrrrc�F��eZdZ�fd�Zd�Z�fd�Zd�Zd�Zd�fd�	Z�xZ	S)	�SentinelManagedConnectionc�n��|�d��|_t��jdi|��dS)N�connection_poolr)�popr�super�__init__)�self�kwargs�	__class__s  �rrz"SentinelManagedConnection.__init__s;���%�z�z�*;�<�<��������"�"�6�"�"�"�"�"rc��|j}t|��j�d|j�d�}|jrd|j�d|j��}||z}|S)N�	<service=z%s>z,host=z,port=)r�typer�service_name�host�port)r �pool�s�	host_infos    r�__repr__z"SentinelManagedConnection.__repr__s]���#���D�z�z�"�C�C�T�->�C�C�C���9�	�=���=�=�$�)�=�=�I��I�
�A��rc���|\|_|_t�����|jjrI|�d��t|�����dkrtd���dSdS)N�PING�PONGzPING failed)
r'r(r�connectr�check_connection�send_commandr�
read_responser)r �addressr"s  �r�
connect_toz$SentinelManagedConnection.connect_to s����&���	�4�9�
����������0�	5����f�%�%�%��D�.�.�0�0�1�1�V�;�;�%�m�4�4�4�	5�	5�;�;rc��|jrdS|jjr.|�|j�����dS|j���D])}	|�|��cS#t$rY�&wxYwt��N)�_sockr�	is_masterr5�get_master_address�
rotate_slavesrr)r �slaves  r�_connect_retryz(SentinelManagedConnection._connect_retry(s����:�	��F���)�	%��O�O�D�0�C�C�E�E�F�F�F�F�F��-�;�;�=�=�
�
����?�?�5�1�1�1�1�1��&�����H�����$�$s� A7�7
B�Bc�D�|j�|jd���S)Nc��dSr7r)�errors r�<lambda>z3SentinelManagedConnection.connect.<locals>.<lambda>8s��$�r)�retry�call_with_retryr=)r s rr0z!SentinelManagedConnection.connect5s(���z�)�)�����
�
�	
rFc����	t���|���S#t$r1|jjr#|���t
d����wxYw)N)�disable_decodingz"The previous master is now a slave)rr3r	rr9�
disconnectr)r rEr"s  �rr3z'SentinelManagedConnection.read_response;sr���	��7�7�(�(�:J�(�K�K�K���		�		�		��#�-�
L����!�!�!�%�&J�K�K�K��		���s	�!%�;A )F)
rrrrr,r5r=r0r3�
__classcell__�r"s@rrrs��������#�#�#�#�#����5�5�5�5�5�%�%�%�
�
�
����������rrc��eZdZdS)�SentinelManagedSSLConnectionNrrrrrJrJJrrrJc�H��eZdZdZ�fd�Zd�Z�fd�Z�fd�Zd�Zd�Z	�xZ
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�p��|�d|�dd��rtnt��|d<|�dd��|_|�dd��|_t
��jdi|��tj	|��|j
d<||_||_dS)	N�connection_class�sslFr9Tr1rr)
�getrrJrr9r1rr�weakref�proxy�connection_kwargsr&�sentinel_manager)r r&rTr!r"s    �rrzSentinelConnectionPool.__init__Vs����%+�Z�Z���z�z�%��'�'�
+�(�(�*�	&
�&
��!�"� ���K��6�6��� &�
�
�+=�u� E� E��������"�"�6�"�"�"�4;�M�$�4G�4G���0�1�(��� 0����rc�\�|jrdnd}t|��j�d|j�d|�d�S)N�masterr<r$�(�))r9r%rr&)r �roles  rr,zSentinelConnectionPool.__repr__ds=���>�6�x�x�w���t�*�*�%�K�K��0A�K�K�D�K�K�K�Krc�d��t�����d|_d|_dSr7)r�reset�master_address�slave_rr_counter)r r"s �rr[zSentinelConnectionPool.reseths*���
���
�
����"��� $����rc���|jp|jo|j|j|jfk}t	��}|o|�|��Sr7)r9r\r'r(r�owns_connection)r �
connection�check�parentr"s    �rr_z&SentinelConnectionPool.owns_connectionmsT����N�"�
��N�X�t�2�z��
��6X�X�	������;��/�/�
�;�;�;rc��|j�|j��}|jr(|j|kr||_|�d���|S)NF)�inuse_connections)rT�discover_masterr&r9r\rF)r r\s  rr:z)SentinelConnectionPool.get_master_addresstsW���.�>�>�t�?P�Q�Q���>�	9��"�n�4�4�&4��#����%��8�8�8��rc#��K�|j�|j��}|r�|j�*t	jdt
|��dz
��|_tt
|����D]2}|jdzt
|��z|_||j}|V��3	|���V�n#t$rYnwxYwtd|j�����)zRound-robin slave balancerNr�zNo slave found for )rT�discover_slavesr&r]�random�randint�len�ranger:rr)r �slaves�_r<s    rr;z$SentinelConnectionPool.rotate_slaves~s������&�6�6�t�7H�I�I���	��$�,�(.��q�#�f�+�+��/�(J�(J��%��3�v�;�;�'�'�
�
��)-�)>��)B�c�&�k�k�(Q��%��t�4�5�������	��)�)�+�+�+�+�+�+��"�	�	�	��D�	���� �!L�t�7H�!L�!L�M�M�Ms�%B<�<
C	�C	)rrr�__doc__rr,r[r_r:r;rGrHs@rrLrLNs����������1�1�1�1�1�L�L�L�%�%�%�%�%�
<�<�<�<�<����N�N�N�N�N�N�NrrLc�Z�eZdZdZ		d
d�Zd�Zd�Zd�Zd�Zd	�Z	d
�Z
eefd�Z
eefd�ZdS)�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.
    rNc���|�d�|���D��}|�_�fd�|D���_|�_|�_dS)Nc�D�i|]\}}|�d���||��S)�socket_)�
startswith)�.0�k�vs   r�
<dictcomp>z%Sentinel.__init__.<locals>.<dictcomp>�s?�������A�a�l�l�9�>U�>U���1���rc�<��g|]\}}t||fi�j����Sr)r�sentinel_kwargs)rv�hostnamer(r s   �r�
<listcomp>z%Sentinel.__init__.<locals>.<listcomp>�sB���
�
�
���$�
�(�D�9�9�D�$8�9�9�
�
�
r)�itemsr{�	sentinels�min_other_sentinelsrS)r rr�r{rSs`    rrzSentinel.__init__�s�����"���!2�!8�!8�!:�!:����O� /���
�
�
�
�"+�
�
�
���$7�� �!2����rc��t|�dd����}d|���vr|�d��|r|jD]}|j|i|���n$t
j|j��j|i|��dS)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)�boolrP�keysrr�execute_commandri�choice)r �argsr!r��sentinels     rr�zSentinel.execute_command�s����F�J�J�v�u�-�-�.�.���V�[�[�]�]�"�"��J�J�v�����	K� �N�
:�
:��(��(�$�9�&�9�9�9�9�
:�
:�F�M�$�.�)�)�9�4�J�6�J�J�J��trc���g}|jD]4}|�d�|jj�����5t|��j�dd�|���d�S)Nz
{host}:{port}z<sentinels=[�,z]>)r�append�
format_maprrSr%r�join)r �sentinel_addressesr�s   rr,zSentinel.__repr__�s�������	�	�H��%�%��*�*��,�>���
�
�
�
�
�t�*�*�%�S�S�3�8�8�<N�3O�3O�S�S�S�Src�`�|dr|ds|drdS|d|jkrdSdS)Nr9�is_sdown�is_odownFznum-other-sentinelsT)r�)r �stater&s   r�check_master_statezSentinel.check_master_state�sJ���[�!�	�U�:�%6�	�%�
�:K�	��5��&�'�$�*B�B�B��5��trc�r�t|j��D]�\}}	|���}n#ttf$rY�.wxYw|�|��}|rH|�||��r2||jdc|jd<|j|<|d|dfcS��td|�����)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(zNo master found for )�	enumerater�sentinel_mastersrrrPr�r)r r&�sentinel_nor��mastersr�s      rrezSentinel.discover_master�s���&/�t�~�%>�%>�	2�	2�!�K��
�"�3�3�5�5����#�\�2�
�
�
���
�����K�K��-�-�E��
2��0�0���E�E�
2���N�1�%�?���q�!�4�>�+�#>��T�{�E�&�M�1�1�1�1��!�"I��"I�"I�J�J�Js�0�A�Ac�|�g}|D]6}|ds|dr�|�|d|df���7|S)z1Remove slaves that are in an ODOWN or SDOWN stater�r�r�r()r�)r rm�slaves_aliver<s    r�
filter_slaveszSentinel.filter_slaves�s\�����	>�	>�E��Z� �
�E�*�$5�
������t��e�F�m� <�=�=�=�=��rc��|jD]Q}	|�|��}n#tttf$rY�2wxYw|�|��}|r|cS�RgS)z;Returns a list of alive slaves for service ``service_name``)r�sentinel_slavesrr
rr�)r r&r�rms    rrhzSentinel.discover_slavess�����	�	�H�
�!�1�1�,�?�?����#�]�L�A�
�
�
���
�����'�'��/�/�F��
��
�
�
�
��	s�!�;�;c��d|d<t|j��}|�|��||||fi|�����S)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.
        Tr9�r��dictrS�update�r r&�redis_class�connection_pool_classr!rSs      r�
master_forzSentinel.master_forsn��:#��{�� ��!7�8�8��� � ��(�(�(��{�1�1��d���&7���
�
�
�	
rc��d|d<t|j��}|�|��||||fi|�����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.
        Fr9r�r�r�s      r�	slave_forzSentinel.slave_for8sn��0$��{�� ��!7�8�8��� � ��(�(�(��{�1�1��d���&7���
�
�
�	
r)rN)rrrrorr�r,r�rer�rhrrLr�r�rrrrqrq�s���������>��	3�3�3�3�,���"T�T�T����K�K�K�.���
�
�
��4�	$
�$
�$
�$
�R�4�	
�
�
�
�
�
rrq)rirQ�redis.clientr�redis.commandsr�redis.connectionrrr�redis.exceptionsrr	r
r�redis.utilsrrrrrJrLrqrrr�<module>r�s���
�
�
�
�����������+�+�+�+�+�+�F�F�F�F�F�F�F�F�F�F�X�X�X�X�X�X�X�X�X�X�X�X�$�$�$�$�$�$�	�	�	�	�	�/�	�	�	�	�	�	�	�	��	�	�	�4�4�4�4�4�
�4�4�4�n	�	�	�	�	�#<�m�	�	�	�?N�?N�?N�?N�?N�^�?N�?N�?N�DG
�G
�G
�G
�G
��G
�G
�G
�G
�G
r