�
J�gE9 � �6 � d dl Z d dlZd dlmZ d dlmZ d dlmZ d dlm Z m
Z
mZ d dlm
Z
mZmZmZ d dlmZ G d� d e
� � Z G d
� de
� � Z G d� d
e � � Z G d� dee� � Z G d� d� � Z G d� de
� � Z G d� de� � ZdS )� N)�Optional)�Redis)�SentinelCommands)�
Connection�ConnectionPool�
SSLConnection)�ConnectionError�
ReadOnlyError�
ResponseError�TimeoutError)�str_if_bytesc � � e Zd ZdS )�MasterNotFoundErrorN��__name__�
__module__�__qualname__� � �^/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/redis/sentinel.pyr r � � � � � � ��Dr r c � � e Zd ZdS )�SlaveNotFoundErrorNr r r r r r r r r c �r � � e Zd Z� fd�Zd� Z� fd�Zd� Zd� Z dddd�dee d ee f� fd
�Z
� xZS )�SentinelManagedConnectionc �n �� |� d� � | _ t � � j di |�� d S )N�connection_poolr )�popr �super�__init__)�self�kwargs� __class__s �r r z"SentinelManagedConnection.__init__ s; �� �%�z�z�*;�<�<��������"�"�6�"�"�"�"�"r c � � | j }dt | � � j � dt | � � j � d|j � d�}| j rd| 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� � ��#��
0��T�
�
�%�
0�
0��T�
�
�(;�
0�
0��)�
0�
0�
0�
� �9� �=���=�=�$�)�=�=�I��I�
�A��r c � �� |\ | _ | _ t � � � � � | j j rI| � d� � t | � � � � � dk rt d� � �d S d S )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�;�;r c � � | j rd S | j j r.| � | j � � � � � d S | j � � � D ])} | � |� � c S # t $ r Y �&w xY wt ��N)�_sockr � is_masterr8 �get_master_address�
rotate_slavesr r )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 � | j d� � � S )Nc � � d S r: r )�errors r �<lambda>z3SentinelManagedConnection.connect.<locals>.<lambda>: s � �T� r )�retry�call_with_retryr@ �r! s r r3 z!SentinelManagedConnection.connect9 s! � ��z�)�)�$�*=�?Q�?Q�R�R�Rr F)�disconnect_on_error�push_requestrH rI c �� �� t � � � |||�� � S # t $ r1 | j j r#| � � � t
d� � �� w xY w)N)�disable_decodingrH rI z"The previous master is now a slave)r r6 r
r r<