o
    iQ                     @   s   d dl mZmZ d dlmZm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 G dd	 d	eZG d
d deZG dd deZe	eeef  ZG dd deeZdS )    )ABCabstractmethod)OptionalUnionN)RedisCluster)WeightedList)CircuitBreaker)Numberc                   @   sp   e Zd ZeedefddZejedefddZeedee	 fddZ
e
jedee	 fd	dZ
d
S )AbstractDatabasereturnc                 C      dS )z]The weight of this database in compare to others. Used to determine the database failover to.N selfr   r   J/home/ubuntu/.local/lib/python3.10/site-packages/redis/multidb/database.pyweight      zAbstractDatabase.weightr   c                 C   r   )z5Set the weight of this database in compare to others.Nr   r   r   r   r   r   r      r   c                 C   r   )z6Health check URL associated with the current database.Nr   r   r   r   r   health_check_url   r   z!AbstractDatabase.health_check_urlr   c                 C   r   )z>Set the health check URL associated with the current database.Nr   r   r   r   r   r   r      r   N)__name__
__module____qualname__propertyr   floatr   setterr   strr   r   r   r   r   r
      s    r
   c                   @   sz   e Zd Z	ddedee fddZedefddZej	defd	dZedee fd
dZ
e
j	dee fddZ
dS )BaseDatabaseNr   r   c                 C   s   || _ || _d S N)_weight_health_check_url)r   r   r   r   r   r   __init__&   s   
zBaseDatabase.__init__r   c                 C      | j S r   r   r   r   r   r   r   .      zBaseDatabase.weightc                 C   
   || _ d S r   r#   r   r   r   r   r   2      
c                 C   r"   r   r    r   r   r   r   r   6   r$   zBaseDatabase.health_check_urlc                 C   r%   r   r'   r   r   r   r   r   :   r&   r   )r   r   r   r   r   r   r!   r   r   r   r   r   r   r   r   r   %   s    
r   c                   @   s   e Zd ZdZeedeeje	f fddZ
e
jedeeje	f fddZ
eedefddZejed	efd
dZdS )SyncDatabasez5Database with an underlying synchronous redis client.r   c                 C   r   )zThe underlying redis client.Nr   r   r   r   r   clientB   r   zSyncDatabase.clientr)   c                 C   r   )z Set the underlying redis client.Nr   r   r)   r   r   r   r)   H   r   c                 C   r   )z)Circuit breaker for the current database.Nr   r   r   r   r   circuitN   r   zSyncDatabase.circuitr+   c                 C   r   )z1Set the circuit breaker for the current database.Nr   r   r+   r   r   r   r+   T   r   N)r   r   r   __doc__r   r   r   redisRedisr   r)   r   r   r+   r   r   r   r   r(   ?   s    r(   c                
       s   e Zd Z	ddeejef dedede	e
 f fddZedeejef fd	d
Zejdeejef fdd
ZedefddZejdefddZdd Z  ZS )DatabaseNr)   r+   r   r   c                    s&   || _ || _| | j_t || dS )at  
        Initialize a new Database instance.

        Args:
            client: Underlying Redis client instance for database operations
            circuit: Circuit breaker for handling database failures
            weight: Weight value used for database failover prioritization
            health_check_url: Health check URL associated with the current database
        N)_client_cbdatabasesuperr!   )r   r)   r+   r   r   	__class__r   r   r!   _   s   zDatabase.__init__r   c                 C   r"   r   r1   r   r   r   r   r)   t   r$   zDatabase.clientc                 C   r%   r   r7   r*   r   r   r   r)   x   r&   c                 C   r"   r   r2   r   r   r   r   r+   |   r$   zDatabase.circuitc                 C   r%   r   r8   r,   r   r   r   r+      r&   c                 C   s   d| j  d| j dS )NzDatabase(client=z	, weight=))r)   r   r   r   r   r   __repr__   s   zDatabase.__repr__r   )r   r   r   r   r.   r/   r   r   r   r   r   r!   r   r)   r   r+   r:   __classcell__r   r   r5   r   r0   ^   s(    r0   )abcr   r   typingr   r   r.   r   redis.data_structurer   redis.multidb.circuitr   redis.typingr	   r
   r   r(   tuple	Databasesr0   r   r   r   r   <module>   s    