
    ng\jL'                        S SK JrJr  S SKJr  S SKJrJrJrJ	r	  S SK
r
S SKJrJrJr  S SKJrJrJr  S SKJrJrJrJrJrJrJrJr  S SKJrJr  S S	KJ r   S S
K!J"r"J#r#  S SK$J%r%  S SK&J'r'J(r(J)r)  S SK*J+r+J,r,  S SK-J.r.J/r/J0r0J1r1  S SK2J3r3J4r4J5r5J6r6J7r7  S SK8J9r9  Sr: " S S\5      r;S\#4S jr<\ " S S5      5       r=\ " S S5      5       r>g)    )	dataclassfield)Enum)ListOptionalTypeUnionN)ConnectionPoolRedisRedisCluster)DEFAULT_RETRY_BASEDEFAULT_RETRY_CAPDEFAULT_RETRY_COUNT)DEFAULT_HEALTH_CHECK_DELAYDEFAULT_HEALTH_CHECK_INTERVALDEFAULT_HEALTH_CHECK_POLICYDEFAULT_HEALTH_CHECK_PROBESDEFAULT_HEALTH_CHECK_TIMEOUTHealthCheckHealthCheckPoliciesPingHealthCheck)ExponentialWithJitterBackoff	NoBackoff)WeightedList)EventDispatcherEventDispatcherInterface)MaintNotificationsConfig)DEFAULT_GRACE_PERIODCircuitBreakerPBCircuitBreakerAdapter)Database	Databases)DEFAULT_FAILOVER_ATTEMPTSDEFAULT_FAILOVER_DELAYFailoverStrategyWeightBasedFailoverStrategy)DEFAULT_FAILURE_RATE_THRESHOLD!DEFAULT_FAILURES_DETECTION_WINDOWDEFAULT_MIN_NUM_FAILURESCommandFailureDetectorFailureDetector)Retryx   c                        \ rS rSrSrSrSrSrg)InitialHealthCheck/   all_availablemajority_availableone_available N)__name__
__module____qualname____firstlineno__ALL_AVAILABLEMAJORITY_AVAILABLEONE_AVAILABLE__static_attributes__r4       O/home/edenadmin/noVNC/venv/lib/python3.13/site-packages/redis/multidb/config.pyr/   r/   /   s    #M-#Mr=   r/   returnc                      [        5       $ N)r   r4   r=   r>   default_event_dispatcherrB   5   s    r=   c                       \ rS rSr% SrSr\\S'   \" \	S9r
\	\S'   Sr\\   \S'   Sr\\   \S	'   Sr\\   \S
'   \r\\S'   Sr\\   \S'   S\4S jrSrg)DatabaseConfig9   a  
Dataclass representing the configuration for a database connection.

This class is used to store configuration settings for a database connection,
including client options, connection sourcing details, circuit breaker settings,
and cluster-specific properties. It provides a structure for defining these
attributes and allows for the creation of customized configurations for various
database setups.

Attributes:
    weight (float): Weight of the database to define the active one.
    client_kwargs (dict): Additional parameters for the database client connection.
    from_url (Optional[str]): Redis URL way of connecting to the database.
    from_pool (Optional[ConnectionPool]): A pre-configured connection pool to use.
    circuit (Optional[CircuitBreaker]): Custom circuit breaker implementation.
    grace_period (float): Grace period after which we need to check if the circuit could be closed again.
    health_check_url (Optional[str]): URL for health checks. Cluster FQDN is typically used
        on public Redis Enterprise endpoints.

Methods:
    default_circuit_breaker:
        Generates and returns a default CircuitBreaker instance adapted for use.
g      ?weightdefault_factoryclient_kwargsNfrom_url	from_poolcircuitgrace_periodhealth_check_urlr?   c                 T    [         R                  " U R                  S9n[        U5      $ )N)reset_timeout)	pybreakerr   rM   r    )selfcircuit_breakers     r>   default_circuit_breaker&DatabaseConfig.default_circuit_breaker[   s#    #22ARARS&77r=   r4   )r5   r6   r7   r8   __doc__rF   float__annotations__r   dictrI   rJ   r   strrK   r
   rL   r   r   rM   rN   rT   r<   r4   r=   r>   rD   rD   9   ss    0 FE5M45"Hhsm"*.Ix'.(,GXn%,.L%.&*hsm*8 8r=   rD   c                      \ rS rSr% Sr\\   \S'   \r	\
\\\4      \S'   \" \" \\S9\S9r\\S'   Sr\\\      \S	'   \r\\S
'   \r\\S'   \r\\S'   Sr\\\      \S'   \ r!\\S'   \"r#\\S'   \$r%\\S'   \&r'\\S'   \(r)\*\S'   Sr+\\,   \S'   \-r.\\S'   \/r0\\S'   \1r2\\S'   \3" \4S9r5\6\S'   \7Rp                  r9\7\S'   S\:4S jr;S\\   4S jr<S\\   4S jr=S\,4S jr>Sr?g) MultiDbConfig`   a\	  
Configuration class for managing multiple database connections in a resilient and fail-safe manner.

Attributes:
    databases_config: A list of database configurations.
    client_class: The client class used to manage database connections.
    command_retry: Retry strategy for executing database commands.
    failure_detectors: Optional list of additional failure detectors for monitoring database failures.
    min_num_failures: Minimal count of failures required for failover
    failure_rate_threshold: Percentage of failures required for failover
    failures_detection_window: Time interval for tracking database failures.
    health_checks: Optional list of additional health checks performed on databases.
    health_check_interval: Time interval for executing health checks.
    health_check_probes: Number of attempts to evaluate the health of a database.
    health_check_delay: Delay between health check attempts.
    health_check_timeout: Timeout for the full health check operation (including all probes).
    health_check_policy: Policy for determining database health based on health checks.
    failover_strategy: Optional strategy for handling database failover scenarios.
    failover_attempts: Number of retries allowed for failover operations.
    failover_delay: Delay between failover attempts.
    auto_fallback_interval: Time interval to trigger automatic fallback.
    event_dispatcher: Interface for dispatching events related to database operations.
    initial_health_check_policy: Defines the policy used to determine whether the databases setup is
                                 healthy during the initial health check.

Methods:
    databases:
        Retrieves a collection of database clients managed by weighted configurations.
        Initializes database clients based on the provided configuration and removes
        redundant retry objects for lower-level clients to rely on global retry logic.

    default_failure_detectors:
        Returns the default list of failure detectors used to monitor database failures.

    default_health_checks:
        Returns the default list of health checks used to monitor database health
        with specific retry and backoff strategies.

    default_failover_strategy:
        Provides the default failover strategy used for handling failover scenarios
        with defined retry and backoff configurations.
databases_configclient_class)basecap)backoffretriescommand_retryNfailure_detectorsmin_num_failuresfailure_rate_thresholdfailures_detection_windowhealth_checkshealth_check_intervalhealth_check_probeshealth_check_delayhealth_check_timeouthealth_check_policyfailover_strategyfailover_attemptsfailover_delayauto_fallback_intervalrG   event_dispatcherinitial_health_check_policyr?   c           
         [        5       nU R                   GHk  n[        S[        5       S9UR                  S'   SUR                  ;  a  [        SS9UR                  S'   UR                  (       a2  U R                  R                  " UR                  40 UR                  D6nO|UR                  (       aO  UR                  R                  [        S[        5       S95        U R                  R                  UR                  S9nOU R                  " S	0 UR                  D6nUR                  c  UR                  5       OUR                  nUR                  [        UUUR                  UR                  S9UR                  5        GMn     U$ )
Nr   )rc   rb   retrymaint_notifications_configF)enabled)connection_pool)clientrL   rF   rN   r4   )r   r^   r,   r   rI   r   rJ   r_   rK   	set_retryrL   rT   addr!   rF   rN   )rR   	databasesdatabase_configrz   rL   s        r>   r}   MultiDbConfig.databases   sq    N	#44O 6;9;6O))'2 ,?3P3PP,U;  --.JK ''**33#,,0?0M0M !**))33!Y[9 **44$3$=$= 5  **K_-J-JK #**2  779$,, 
 MM!#*11%4%E%E	  &&C  5V r=   c                 V    [        U R                  U R                  U R                  S9/$ )N)rf   rg   failure_detection_window)r*   rf   rg   rh   rR   s    r>   default_failure_detectors'MultiDbConfig.default_failure_detectors   s/    "!%!6!6'+'B'B)-)G)G
 	
r=   c                 V    [        U R                  U R                  U R                  S9/$ )N)rk   rl   rm   )r   rk   rl   rm   r   s    r>   default_health_checks#MultiDbConfig.default_health_checks   s/    $($<$<#'#:#:%)%>%>
 	
r=   c                     [        5       $ rA   )r&   r   s    r>   default_failover_strategy'MultiDbConfig.default_failover_strategy   s    *,,r=   r4   )@r5   r6   r7   r8   rV   r   rD   rX   r   r_   r   r	   r   r,   r   r   r   r   rd   re   r   r+   r)   rf   intr'   rg   rW   r(   rh   ri   r   r   rj   r   rk   r   rl   r   rm   r   rn   r   ro   r%   r#   rp   r$   rq   DEFAULT_AUTO_FALLBACK_INTERVALrr   r   rB   rs   r   r/   r9   rt   r"   r}   r   r   r   r<   r4   r=   r>   r\   r\   `   sn   )V >**5:L$uUL012: ,#):
 $	M5  :>x_ 56=4c4$BEB'HuH15M8D-.5#@5@:: ::">%>/J,J48x 0186s62NE2$BEB1602.  7I6V6V!3V.9 .`
4+@ 

tK'8 
-+; -r=   r\   )?dataclassesr   r   enumr   typingr   r   r   r	   rQ   redisr
   r   r   redis._defaultsr   r   r   !redis.asyncio.multidb.healthcheckr   r   r   r   r   r   r   r   redis.backoffr   r   redis.data_structurer   redis.eventr   r   redis.maint_notificationsr   redis.multidb.circuitr   r   r    redis.multidb.databaser!   r"   redis.multidb.failoverr#   r$   r%   r&   redis.multidb.failure_detectorr'   r(   r)   r*   r+   redis.retryr,   r   r/   rB   rD   r\   r4   r=   r>   <module>r      s    (  . .  5 5 V V	 	 	 B - A > 
 7   !$ $ $":  #8 #8 #8L J- J- J-r=   