Registry / database / node-redis-warlock

node-redis-warlock

JSON →
library1.0.2jsnpmunverified

node-redis-warlock is a distributed locking library for Node.js using Redis, version 1.0.2. It provides battle-hardened locking mechanisms such as simple lock, optimistic lock with retries, unlocking by lock ID, and TTL modification. It requires node-redis (v0.10 compatible) and Redis v2.6.12+. The library is synchronous in style, relying on callbacks rather than promises or async/await, which is a key differentiator from modern Redis locking libraries like redlock that support promises. Release cadence is sporadic; no recent updates.

npm install node-redis-warlock
INSTALL
IMPORT
SIG · NODE-REDIS-WARLOCK
N
node-redis-warlock
databasejavascriptv1.0.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Warlock
const Warlock = require('node-redis-warlock');
import Warlock from 'node-redis-warlock';
The package does not support ESM. Use CommonJS require.
warlock.lock
warlock.lock(key, ttl, (err, unlock) => { ... });
warlock.lock(key, ttl).then(...);
lock is callback-based, not promise-based.
warlock.optimistic
warlock.optimistic(key, ttl, maxAttempts, wait, (err, unlock) => {});
Optimistic locking with retry. Cannot promisify directly.
warlock.unlock
warlock.unlock(key, lockId, (err, result) => {});
Unlock by lock ID, not just the key.

Connects to Redis, creates a warlock instance, acquires a lock, does work, then releases the lock.

const Redis = require('redis'); const Warlock = require('node-redis-warlock'); const redis = Redis.createClient({ url: process.env.REDIS_URL || 'redis://localhost:6379' }); const warlock = Warlock(redis); const key = 'my-lock'; const ttl = 5000; warlock.lock(key, ttl, (err, unlock, id) => { if (err) { console.error('Lock error:', err); return; } if (typeof unlock === 'function') { console.log('Lock acquired'); // Do critical work setTimeout(() => { unlock(); console.log('Lock released'); redis.quit(); }, 1000); } else { console.log('Could not acquire lock'); redis.quit(); } });
Debug
Known issues
gotchaThe callback for lock receives (err, unlock, id); unlock is a function that releases the lock. If the lock is not acquired, unlock is not a function (null or undefined).
fix
Check typeof unlock === 'function' before calling it.
affects: >=0.0.1
gotchalock returns a lock ID as third argument; use unlock with that ID to release the lock. Using unlock without ID may not work.
fix
Always pass the lock ID to warlock.unlock().
affects: >=0.0.1
gotchaThe module requires a Redis client from the 'redis' npm package (v0.10 compatible). It will not work with ioredis or other Redis clients.
fix
Use the 'redis' package (not 'ioredis') to create the client.
affects: >=0.0.1
deprecatedThe 'redis' package v0.10 is outdated; modern versions (v3+) have breaking API changes (e.g., no callback in createClient).
fix
Use 'redis' v2.8 or later, but ensure compatibility with callback style.
affects: >=1.0.0
gotchaoptimistic locks may fail after maxAttempts; the callback receives (err, unlock) where unlock may be undefined.
fix
Always check if unlock is a function before calling it.
affects: >=0.0.1
Errors
Common errors & fixes
TypeError: warlock.lock is not a function
Incorrect import: using ES import instead of require.
fix
Use const Warlock = require('node-redis-warlock'); then const warlock = Warlock(redis);
Unlock is not a function
Lock was not acquired; calling unlock without checking type.
fix
Check typeof unlock === 'function' before calling unlock().
Redis connection error: RedisClient is not a constructor
Using 'ioredis' instead of 'redis' package.
fix
Install and use 'redis' npm package (npm install redis).
Upgrade
Version history
1.0.2latest on npm
Audit
Dependencies
redisrequiredNeed a Redis client instance to create the locker.
Agent activity
4 hits · last 30 days
node
4
Resources
node-redis-warlock — npm install node-redis-warlock · libregistry