Registry / database / redislock

redislock

JSON →
library1.3.0jsnpmunverified

Node distributed locking using Redis with atomic Lua scripts. Current stable version 1.3.0. Low release cadence (last update years ago). Differentiator: uses SET key uuid PX timeout NX for acquire and Lua scripts for release/extend, avoiding race conditions without requiring dedicated Redis connections. Supports callbacks, promises (bluebird), and co. Compatible with Redis >= 2.6.12. Provides LockAcquisitionError, LockReleaseError, LockExtendError for error handling.

npm install redislock
INSTALL
IMPORT
SIG · REDISLOCK
R
redislock
databasejavascriptv1.3.0
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.

redislock
import redislock from 'redislock'
const redislock = require('redislock')
CommonJS require works but TypeScript/ESM users should use default import.
createLock
import { createLock } from 'redislock'
const createLock = require('redislock').createLock
Named export available; both work in CommonJS, but ESM prefers named import.
LockAcquisitionError
import { LockAcquisitionError } from 'redislock'
Error classes are exported and can be used with instanceof checks.

Creates a Redis lock with timeout, retries, and delay, acquires it, performs work, and releases it using async/await.

import redis from 'redis'; import redislock from 'redislock'; const client = redis.createClient(); const lock = redislock.createLock(client, { timeout: 20000, retries: 3, delay: 100 }); async function criticalSection() { try { await lock.acquire('app:feature:lock'); // locked - do work console.log('Lock acquired'); await lock.release(); console.log('Lock released'); } catch (err) { console.error(err); } finally { client.quit(); } } criticalSection();
Debug
Known issues
gotchaLock timeout must be longer than the expected critical section execution, otherwise the lock may expire prematurely.
fix
Set timeout sufficiently high to cover the longest expected operation under the lock.
affects: >=1.0.0
gotchaThe lock is not reentrant; a second acquire on the same key by the same client will fail unless released first.
fix
Design critical sections to not re-enter the same lock, or use a different pattern.
affects: >=1.0.0
deprecatedThe package has not been updated for years and depends on older node_redis. Consider using ioredis-based locking libraries.
fix
Evaluate alternatives like redlock or ioredis's built-in locking.
affects: >=1.0.0
Errors
Common errors & fixes
Error: The lock could not be acquired (LockAcquisitionError)
Maximum retries exhausted without acquiring the lock.
fix
Increase retries or delay, release other locks, or check Redis connectivity.
Error: The lock could not be released (LockReleaseError)
Redis command failed or lock key no longer exists (e.g., expired).
fix
Ensure the lock is still held and Redis is available; handle errors gracefully.
TypeError: client.set is not a function
Using a Redis client that doesn't have the set method, e.g., ioredis instead of node_redis.
fix
Use node_redis (redis) package for compatibility with redislock.
Upgrade
Version history
1.3.0latest on npm
Audit
Dependencies
redisrequiredredislock requires a node_redis client instance to create locks
bluebirdoptionalUsed for promise support; included as own dependency, not external
Agent activity
6 hits · last 30 days
node
6
Resources
redislock — npm install redislock · libregistry