Redis-based distributed mutex (lock) and semaphore implementations for Node.js applications. Current stable version 5.7.0. Actively maintained with regular releases. Key differentiators: fully atomic operations using LUA scripts (fail-safe), built-in lock auto-refresh, optional lock-loss detection, and a simple API. Compared to alternatives like 'redlock', redis-semaphore offers more fine-grained control over lock timeout, acquire attempts, and refresh intervals, plus explicit lost-lock handling. Works exclusively with ioredis client. Ships TypeScript types.
npm install redis-semaphoreNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates creating a Mutex instance, acquiring the lock, executing critical code, and releasing the lock with error handling.
Pass explicit lockTimeout (e.g., 0 for no expiry, though not recommended) to preserve old behavior.
Upgrade Node.js to v14.17.0 or later.
Use `acquireAttemptsLimit: Infinity` or `Number.POSITIVE_INFINITY` as needed.
Understand that release is idempotent and safe to call unconditionally.
Use unique identifiers (e.g., from crypto.randomUUID()) unless you explicitly need to share the lock.
Provide an onLockLost callback to avoid unhandled errors, or catch LostLockError globally.
Ensure lockTimeout is a number, e.g., `{ lockTimeout: 10000 }`.Install and use `ioredis` as the client: `npm install ioredis` and pass an instance.
Either handle the error via onLockLost callback, or avoid long-running critical sections that exceed lockTimeout.