Redis-based distributed locking primitive for Node.js, implementing the algorithm described in the Redis SETNX documentation. Fully non-blocking and asynchronous, designed for concurrency control in distributed systems. Current stable version: 1.0.0. Requires node-redis v4 (breaking change from earlier versions). Retry delay and timeout configurable. Lightweight with minimal dependencies. Used in production at errorception.
npm install redis-lockNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates acquiring a lock, performing async work, and releasing the lock with redis-lock using node-redis v4.
Upgrade to node-redis v4 and ensure client.connect() is called before any lock() call.
If you need longer locks, increase the timeout value passed to lock() or ensure your work completes within the timeout.
Ensure robust error handling and consider using a more sophisticated locking mechanism like Redlock for production critical paths.
Consider using actively maintained alternatives like redlock or ioredis-based locks.
Ensure you call require('redis-lock') with the client: const lock = require('redis-lock')(client);Add await client.connect(); before any lock() call.
Increase the lock timeout or retry delay (second argument to initializer). Ensure the other process releases the lock promptly.
Use const done = await lock('myLock'); then await done(); to release.