Acquire multiple locks atomically in a single Redis operation
IMPORTANT - Deadlock Prevention: Keys are automatically sorted alphabetically before acquisition to prevent deadlocks. The returned lock handles will be in SORTED key order, NOT the original input order.
Atomicity Guarantee: All locks are acquired atomically using a Lua script - either all succeed or none do. Redis guarantees that Lua scripts execute atomically without interruption.
Retry Behavior: When a key is already locked, acquireBatch will retry according to the configured retryAttempts and retryDelay options. This allows handling temporary lock contention.
Example:
// Input: ['user:3', 'user:1', 'user:2']
const handles = await manager.acquireBatch(['user:3', 'user:1', 'user:2']);
// Returns handles in sorted order: ['user:1', 'user:2', 'user:3']
Array of lock keys to acquire (will be sorted internally)
Acquisition options
Optional ReadonlynodeIndex?: numberRedis node index to use (defaults to 0)
Optional ReadonlyretryAttempts?: numberNumber of retry attempts (defaults to manager's defaultRetryAttempts)
Optional ReadonlyretryDelay?: numberDelay between retries in milliseconds (defaults to manager's defaultRetryDelay)
Optional Readonlyttl?: numberLock time-to-live in milliseconds (defaults to manager's defaultTTL)
Promise resolving to array of lock handles in SORTED key order
Acquire a lock with automatic tracking
Clean up expired locks from tracking
Create a distributed RedLock for multiple Redis instances
Create a simple lock for single Redis instance
Get list of currently active locks
Get metrics in Prometheus format (if monitoring enabled)
Get current lock statistics
Release multiple locks
Array of lock handles to release
Promise resolving to array of results (true if released, false if already expired)
Acquire and manage multiple locks with automatic extension Combines batch acquisition with auto-extension for long-running operations
Array of lock keys to acquire
Function to execute while holding all locks
Lock configuration options
Optional ReadonlynodeIndex?: numberRedis node index to use (defaults to 0)
Optional ReadonlyretryAttempts?: numberNumber of retry attempts (defaults to manager's defaultRetryAttempts)
Optional ReadonlyretryDelay?: numberDelay between retries in milliseconds (defaults to manager's defaultRetryDelay)
Optional Readonlyttl?: numberLock time-to-live in milliseconds (defaults to manager's defaultTTL)
Promise resolving to the routine result
Production-ready lock manager for Redis distributed locking Provides centralized management of locks with monitoring and health checks