/** * True Redlock algorithm implementation with native AbortController * Based on the official Redlock specification */ import { EventEmitter } from "events"; import { RedisClient } from "../core/types"; import { Logger } from "../core/logger"; export interface RedlockOptions { /** * Expected clock drift factor */ driftFactor: number; /** * Number of retry attempts */ retryCount: number; /** * Delay between retries (ms) */ retryDelay: number; /** * Random jitter for retry delay (ms) */ retryJitter: number; /** * Automatically extend locks before expiration */ automaticExtensionThreshold: number; } export interface RedlockResource { resources: string[]; value: string; ttl: number; validity: number; } /** * Simple Redlock-specific Lua scripts * These are intentionally separate from the main scripts.ts as they implement * the pure Redlock algorithm without additional features */ /** * Internal implementation of Redlock lock instance. * @internal This is an internal implementation detail. Use RedlockToolkit instead. */ export declare class InternalRedlockLock { readonly redlock: InternalRedlock; readonly resources: string[]; readonly value: string; readonly ttl: number; private _validity; private autoExtensionManager?; private abortController?; constructor(redlock: InternalRedlock, resource: RedlockResource); /** * Get lock validity expiration timestamp */ get validity(): number; /** * Get remaining validity time */ get remainingTtl(): number; /** * Check if lock is still valid */ get isValid(): boolean; /** * Extend the lock */ extend(ttl: number): Promise; /** * Release the lock */ release(): Promise; /** * Execute function with automatic lock extension */ using(routine: (signal: AbortSignal) => Promise, options?: { extensionTtl?: number; }): Promise; } /** * Internal implementation of the Redlock algorithm. * @internal This is an internal implementation detail. Use RedlockToolkit instead. */ export declare class InternalRedlock extends EventEmitter { protected readonly clients: RedisClient[]; readonly options: RedlockOptions; readonly logger: Logger; private scriptsLoaded; constructor(clients: RedisClient[], options?: Partial, logger?: Logger); /** * Acquire a distributed lock using Redlock algorithm */ acquire(resources: string | string[], ttl: number, options?: Partial): Promise; /** * Extend an existing lock */ extend(lock: InternalRedlockLock, ttl: number): Promise; /** * Release a lock */ release(lock: InternalRedlockLock): Promise; /** * Force release a lock (without ownership check). * * DANGER: this deletes the lock keys unconditionally, even if the lock is * currently held by a different owner. Never call this automatically; * it exists only for manual operator intervention. */ forceRelease(lock: InternalRedlockLock): Promise; /** * Execute function with automatic lock management */ using(resources: string | string[], ttl: number, routine: (signal: AbortSignal) => Promise, options?: Partial): Promise; /** * Attempt to acquire lock with quorum consensus */ private attemptLock; /** * Execute Lua script with fallback */ private executeScript; /** * Generate unique lock value */ private generateValue; /** * Calculate retry delay with jitter */ private calculateRetryDelay; /** * Sleep utility */ private sleep; } export default InternalRedlock; //# sourceMappingURL=redlock.d.ts.map