A distributed lock implementation for Redis based on the Redlock algorithm. The current stable version is 4.x (note: 5.0.0-beta.3 is prerelease). It provides strong locking guarantees for both single-redis and multi-redis environments with fault tolerance. Key differentiators include built-in lock extension via the `using` API with abort signals, automatic retry with configurable jitter, and TypeScript types. Ships as ESM with CommonJS fallback since version 5.
npm install redlock2No compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows basic usage of Redlock with ioredis, including lock acquisition via the `using` method.
If using CommonJS, use `const Redlock = (await import('redlock')).default` or switch to ESM.Run `npm install ioredis` alongside `npm install redlock`.
Ensure the second parameter to `acquire` or `using` is an integer (e.g., 5000, not 5000.5).
Treat Redlock options as immutable after instantiation.
Always replace the old lock variable with the result of `lock.extend()`.
Remove event listeners for 'lock' and 'unlock'. Use the `using` API instead.
Pass an array of ioredis clients: `new Redlock([client])`.
Use `const Redlock = require('redlock').default` or switch to ESM.Handle `ResourceLockedError` and retry. Ensure at least 3 Redis instances for fault tolerance.
Use `const { ResourceLockedError } = require('redlock')`.