Registry / database / redis-promise-lock

redis-promise-lock

JSON →
library1.0.4jsnpmunverified

Simple promise-based Redis distributed lock for Node.js. Current stable version 1.0.4. Works with redis 4.x. Minimalist design: no bells, no whistles. Provides configurable retry limit, retry delay, and TTL per lock. Pure ESM with TypeScript definitions. Differentiates from alternatives (e.g., redlock) by simplicity and zero dependencies (only peer dependency on the redis client). Release cadence: low, last release 2024.

npm install redis-promise-lock
INSTALL
IMPORT
SIG · REDIS-PROMISE-LOCK
R
redis-promise-lock
databasejavascriptv1.0.4
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.

Lock
import { Lock } from 'redis-promise-lock'
const Lock = require('redis-promise-lock')
Package is ESM-only. CommonJS require() will fail.
Lock
import Lock from 'redis-promise-lock'
import { lock } from 'redis-promise-lock'
Default export does not exist. Must use named import with capital L.
Lock
import type { Lock } from 'redis-promise-lock'
TypeScript users can import the type if only using for type annotations.

Creates a Lock instance with a Redis client, acquires a lock, performs work, then releases the lock. Shows options and basic usage.

import { createClient } from 'redis'; import { Lock } from 'redis-promise-lock'; const client = createClient({ url: 'redis://127.0.0.1:6379' }); await client.connect(); const locker = new Lock(client, { retryLimit: 10, retryDelay: 100, ttl: 3 }); await locker.acquireLock('my-lock'); // critical section await locker.releaseLock('my-lock'); await client.disconnect();
Debug
Known issues
breakingPackage is ESM-only; does not support CommonJS require().
fix
Use import instead of require(). Ensure your project is configured for ESM.
affects: >=1.0.0
deprecatedThe ttl option default changed from 0 (no TTL) to 3 seconds in v1.0.0.
fix
If you relied on no TTL, set ttl: 0 explicitly.
affects: >=1.0.0
breakingConstructor no longer accepts a Redis client as first argument without options in v1.0.0.
fix
Pass options object as second argument. client is still required.
affects: <1.0.0
gotchaLock keys are not automatically prefixed. Multiple instances with same key will conflict if not namespaced.
fix
Prefix your lock keys with a unique identifier per application instance.
affects: >=1.0.0
gotchaAlways release locks in a finally block to avoid deadlocks on error.
fix
Use try/finally: try { await locker.acquireLock('lock') } finally { await locker.releaseLock('lock') }
affects: >=1.0.0
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module
Trying to use require() on an ESM-only package.
fix
Change to import statement: import { Lock } from 'redis-promise-lock'
TypeError: client.connect is not a function
Using redis v3 client without connect method.
fix
Upgrade to redis v4 and call client.connect() before using Lock.
UnhandledPromiseRejection: Error: Lock 'my-lock' not acquired
Failed to acquire lock after retries exhausted.
fix
Increase retryLimit or retryDelay, or check that Redis is reachable and lock is not held indefinitely.
Upgrade
Version history
1.0.4latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
17 hits · last 30 days
node
14
Meta
1
Resources
redis-promise-lock — npm install redis-promise-lock · libregistry