
    1i
                         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      Z G d d	e	      Z G d
 de	      Z G d de	      Zy)    )List)Redis)AsyncDatabase)AsyncFailureDetector)AsyncEventListenerInterfaceAsyncOnCommandsFailEventc                   l    e Zd ZdZdedefdZedefd       Zedefd       Zed        Z	ed	        Z
y
)AsyncActiveDatabaseChangedzE
    Event fired when an async active database has been changed.
    old_databasenew_databasec                 <    || _         || _        || _        || _        y N)_old_database_new_database_command_executor_kwargs)selfr   r   command_executorkwargss        e/mnt/e/genesis-system/.venvs/voice-bridge/lib/python3.12/site-packages/redis/asyncio/multidb/event.py__init__z#AsyncActiveDatabaseChanged.__init__   s#     *)!1    returnc                     | j                   S r   )r   r   s    r   r   z'AsyncActiveDatabaseChanged.old_database       !!!r   c                     | j                   S r   )r   r   s    r   r   z'AsyncActiveDatabaseChanged.new_database   r   r   c                     | j                   S r   )r   r   s    r   r   z+AsyncActiveDatabaseChanged.command_executor"   s    %%%r   c                     | j                   S r   )r   r   s    r   r   z!AsyncActiveDatabaseChanged.kwargs&   s    ||r   N)__name__
__module____qualname____doc__r   r   propertyr   r   r   r    r   r   r
   r
   	   s|    
#
 $
 "m " " "m " " & &  r   r
   c                       e Zd ZdZdefdZy)"ResubscribeOnActiveDatabaseChangedzO
    Re-subscribe the currently active pub / sub to a new active database.
    eventc                 n  K   |j                   j                  }| |j                  j                  j                  di |j
                  }|j                  |_        |j                  |_        |j                  d        d {    ||j                   _        |j                          d {    y y 7 /7 w)Nr%   )
r   active_pubsubr   clientpubsubr   channelspatterns
on_connectaclose)r   r(   
old_pubsub
new_pubsubs       r   listenz)ResubscribeOnActiveDatabaseChanged.listen0   s     ++99
!9++2299IELLIJ","5"5J","5"5J''---3=E""0##%%% "
 .%s$   A?B5B1(B5*B3+B53B5Nr    r!   r"   r#   r
   r3   r%   r   r   r'   r'   +   s    
&"< 
&r   r'   c                       e Zd ZdZdefdZy)&CloseConnectionOnActiveDatabaseChangedz6
    Close connection to the old active database.
    r(   c                   K   |j                   j                  j                          d {    t        |j                   j                  t              rm|j                   j                  j
                  j                          d {    |j                   j                  j
                  j                          d {    y y 7 7 >7 
wr   )r   r+   r0   
isinstancer   connection_pool'update_active_connections_for_reconnect
disconnect)r   r(   s     r   r3   z-CloseConnectionOnActiveDatabaseChanged.listenB   s       ''..000e((//7$$++;;cceee$$++;;FFHHH 8 	1 fHs4   (CCACC5C:C;CCCNr4   r%   r   r   r6   r6   =   s    I"< Ir   r6   c                   2    e Zd ZdZdee   fdZdeddfdZy)RegisterCommandFailureza
    Event listener that registers command failures and passing it to the failure detectors.
    failure_detectorsc                     || _         y r   )_failure_detectors)r   r>   s     r   r   zRegisterCommandFailure.__init__O   s
    "3r   r(   r   Nc                    K   | j                   D ]0  }|j                  |j                  |j                         d {    2 y 7 wr   )r@   register_failure	exceptioncommands)r   r(   failure_detectors      r   r3   zRegisterCommandFailure.listenR   s?      $ 7 7 	U"33EOOU^^TTT	UTs   9AAA)	r    r!   r"   r#   r   r   r   r   r3   r%   r   r   r=   r=   J   s0    4$/C*D 4U": Ut Ur   r=   N)typingr   redis.asyncior   redis.asyncio.multidb.databaser   &redis.asyncio.multidb.failure_detectorr   redis.eventr   r   r
   r'   r6   r=   r%   r   r   <module>rK      sJ      8 G M D&)D &$
I-H 
I
U8 
Ur   