o
    i
                     @   s   d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	m
Z
 G dd dZG dd	 d	e	ZG d
d de	ZG dd de	ZdS )    )List)Redis)AsyncDatabase)AsyncFailureDetector)AsyncEventListenerInterfaceAsyncOnCommandsFailEventc                   @   s^   e Zd ZdZdedefddZedefddZedefd	d
Zedd Z	edd Z
dS )AsyncActiveDatabaseChangedzE
    Event fired when an async active database has been changed.
    old_databasenew_databasec                 K   s   || _ || _|| _|| _d S N)_old_database_new_database_command_executor_kwargs)selfr	   r
   command_executorkwargs r   R/home/app/Keep/.python/lib/python3.10/site-packages/redis/asyncio/multidb/event.py__init__   s   
z#AsyncActiveDatabaseChanged.__init__returnc                 C      | j S r   )r   r   r   r   r   r	         z'AsyncActiveDatabaseChanged.old_databasec                 C   r   r   )r   r   r   r   r   r
      r   z'AsyncActiveDatabaseChanged.new_databasec                 C   r   r   )r   r   r   r   r   r   "   r   z+AsyncActiveDatabaseChanged.command_executorc                 C   r   r   )r   r   r   r   r   r   &   r   z!AsyncActiveDatabaseChanged.kwargsN)__name__
__module____qualname____doc__r   r   propertyr	   r
   r   r   r   r   r   r   r   	   s    

r   c                   @      e Zd ZdZdefddZdS )"ResubscribeOnActiveDatabaseChangedzO
    Re-subscribe the currently active pub / sub to a new active database.
    eventc                    sf   |j j}|d ur1|jjjdi |j}|j|_|j|_|d I d H  ||j _|	 I d H  d S d S )Nr   )
r   Zactive_pubsubr
   clientZpubsubr   ZchannelspatternsZ
on_connectaclose)r   r!   Z
old_pubsubZ
new_pubsubr   r   r   listen0   s   z)ResubscribeOnActiveDatabaseChanged.listenNr   r   r   r   r   r%   r   r   r   r   r    +       r    c                   @   r   )&CloseConnectionOnActiveDatabaseChangedz6
    Close connection to the old active database.
    r!   c                    sR   |j j I d H  t|j jtr'|j jj I d H  |j jj I d H  d S d S r   )r	   r"   r$   
isinstancer   Zconnection_poolZ'update_active_connections_for_reconnectZ
disconnect)r   r!   r   r   r   r%   B   s   z-CloseConnectionOnActiveDatabaseChanged.listenNr&   r   r   r   r   r(   =   r'   r(   c                   @   s4   e Zd ZdZdee fddZdeddfdd	ZdS )
RegisterCommandFailureza
    Event listener that registers command failures and passing it to the failure detectors.
    failure_detectorsc                 C   s
   || _ d S r   )_failure_detectors)r   r+   r   r   r   r   O   s   
zRegisterCommandFailure.__init__r!   r   Nc                    s(   | j D ]}||j|jI d H  qd S r   )r,   Zregister_failure	exceptioncommands)r   r!   Zfailure_detectorr   r   r   r%   R   s   
zRegisterCommandFailure.listen)	r   r   r   r   r   r   r   r   r%   r   r   r   r   r*   J   s    r*   N)typingr   Zredis.asyncior   Zredis.asyncio.multidb.databaser   Z&redis.asyncio.multidb.failure_detectorr   Zredis.eventr   r   r   r    r(   r*   r   r   r   r   <module>   s    "