/** * Circuit Breaker Implementation * Protects against cascading failures and provides fault tolerance */ import { CircuitBreakerOptions, CircuitBreakerMetrics } from "../core/types"; import { EventEmitter } from "events"; export type CircuitState = "closed" | "open" | "half-open"; /** * Circuit Breaker for protecting Redis operations */ export declare class CircuitBreaker extends EventEmitter { private state; private failureCount; private consecutiveFailures; private halfOpenProbes; private lastFailureTime?; private lastOpenTime?; private successCount; private totalOperations; private readonly options; constructor(options?: CircuitBreakerOptions); /** * Validate circuit breaker configuration */ private validateOptions; /** * Execute operation with circuit breaker protection */ execute(operation: () => Promise): Promise; /** * Execute operation with timeout */ private executeWithTimeout; /** * Handle successful operation */ private onSuccess; /** * Handle failed operation */ private onFailure; /** * Open the circuit */ private openCircuit; /** * Reset the circuit to closed state */ private reset; /** * Check if circuit should transition to half-open */ private checkCircuitState; /** * Check if enough time has passed to attempt reset */ private shouldAttemptReset; /** * Get current circuit breaker metrics */ getMetrics(): CircuitBreakerMetrics; /** * Get current state */ getState(): CircuitState; /** * Check if circuit is currently allowing operations */ isOperationAllowed(): boolean; /** * Manually reset the circuit breaker */ manualReset(): void; /** * Get health status */ getHealthStatus(): { healthy: boolean; state: CircuitState; failureRate: number; timeSinceLastFailure?: number; }; } /** * Circuit Breaker Manager for multiple Redis clients */ export declare class CircuitBreakerManager { private breakers; private defaultOptions; constructor(defaultOptions?: CircuitBreakerOptions); /** * Get or create circuit breaker for client */ getBreaker(clientId: string, options?: CircuitBreakerOptions): CircuitBreaker; /** * Execute operation with circuit breaker for specific client */ execute(clientId: string, operation: () => Promise, options?: CircuitBreakerOptions): Promise; /** * Get metrics for all circuit breakers */ getAllMetrics(): Map; /** * Get health status for all circuit breakers */ getOverallHealthStatus(): { healthy: boolean; totalClients: number; healthyClients: number; details: Map>; }; /** * Reset all circuit breakers */ resetAll(): void; /** * Remove circuit breaker for client */ removeBreaker(clientId: string): void; /** * Clear all circuit breakers */ clear(): void; private listeners; on(event: string, listener: (...args: unknown[]) => void): this; emit(event: string, ...args: unknown[]): boolean; } //# sourceMappingURL=circuit-breaker.d.ts.map