/** * True Redlock algorithm implementation with native AbortController * Based on the official Redlock specification */ import { EventEmitter } from "events"; import { RedisClient } from "./types"; 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 { resource: string; value: string; ttl: number; validity: number; } export declare class RedlockLock { readonly redlock: Redlock; readonly resource: string; readonly value: string; readonly ttl: number; readonly validity: number; private extensionTimer?; private abortController?; constructor(redlock: Redlock, resource: RedlockResource); /** * 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; private startAutoExtension; private stopAutoExtension; } export declare class Redlock extends EventEmitter { protected readonly clients: RedisClient[]; readonly options: RedlockOptions; private scriptsLoaded; constructor(clients: RedisClient[], options?: Partial); /** * Acquire a distributed lock using Redlock algorithm */ acquire(resources: string | string[], ttl: number, options?: Partial): Promise; /** * Extend an existing lock */ extend(lock: RedlockLock, ttl: number): Promise; /** * Release a lock */ release(lock: RedlockLock): Promise; /** * Force release a lock (without ownership check) */ forceRelease(lock: RedlockLock): 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 Redlock; //# sourceMappingURL=redlock.d.ts.map