import { Redis as IORedis } from 'ioredis'; import { Lock, LockManager, LockOptions } from '../interfaces/lock'; /** * Options for Redis lock manager */ export interface RedisLockOptions { /** * Key prefix for locks */ lockPrefix?: string; /** * Default lock TTL in milliseconds */ defaultTtl?: number; /** * Default retry delay in milliseconds */ defaultRetryDelay?: number; /** * Default maximum number of retry attempts */ defaultMaxRetries?: number; /** * Whether to enable drift protection * Prevents locks from being deleted by other processes after they expire but before they're released */ driftFactor?: number; /** * Whether to enable logging */ enableLogging?: boolean; /** * Log level */ logLevel?: 'debug' | 'info' | 'warn' | 'error'; } /** * Redis-based distributed lock manager * Uses Redis to coordinate locks across multiple processes or servers */ export declare class RedisLockManager implements LockManager { private client; private options; private logger; private autoExtenders; private static readonly RELEASE_SCRIPT; private static readonly EXTEND_SCRIPT; /** * Creates a new RedisLockManager * @param client Redis client * @param options Lock manager options */ constructor(client: IORedis, options?: RedisLockOptions); /** * Acquire a lock on a resource * @param resource Resource to lock * @param ttl Time-to-live for the lock in milliseconds * @param options Additional lock options * @returns Promise resolving to the acquired lock or null if not acquired */ acquire(resource: string, ttl?: number, options?: LockOptions): Promise; /** * Release a previously acquired lock * @param lock The lock to release * @returns Promise resolving to true if the lock was released */ release(lock: Lock): Promise; /** * Extend the TTL of an existing lock * @param lock The lock to extend * @param ttl Additional time in milliseconds to add to the lock TTL * @returns Promise resolving to the updated lock or null if extension failed */ extend(lock: Lock, ttl: number): Promise; /** * Check if a lock exists on a resource * @param resource Resource to check * @returns Promise resolving to the existing lock or null if not locked */ check(resource: string): Promise; /** * Get all locks * @returns Promise resolving to a map of resource-to-lock mappings */ getAll(): Promise>; /** * Clear all locks (for administrative purposes) * @returns Promise resolving to true if successful */ clear(): Promise; /** * Execute a function within a lock * @param resource Resource to lock * @param fn Function to execute with the lock * @param ttl Time-to-live for the lock in milliseconds * @param options Additional lock options * @returns Promise resolving to the function result */ withLock(resource: string, fn: (lock: Lock) => Promise, ttl?: number, options?: LockOptions): Promise; /** * Set up automatic extension for a lock * @param lock Lock to extend * @param ttl Lock TTL in milliseconds * @param interval Extension interval in milliseconds */ private setupAutoExtension; /** * Stop automatic extension for a lock * @param lock Lock to stop extending */ private stopAutoExtension; /** * Get the Redis key for a lock * @param resource Resource name * @returns Redis key */ private getLockKey; /** * Get the resource name from a lock key * @param key Lock key * @returns Resource name */ private getResourceFromKey; } //# sourceMappingURL=redis-lock.d.ts.map