Registry / storage / ioredfour

ioredfour

JSON →
library1.4.1jsnpmunverified

A Redis binary semaphore (distributed lock) using ioredis. v1.4.1 is the latest stable release. Forked from redfour, it replaces node_redis with ioredis for better performance and supports Redis Cluster (including sharded pub/sub for release notifications). It implements a lock with configurable TTL, minimum replication count, and replication timeout. Active development, low release cadence.

npm install ioredfour
INSTALL
IMPORT
SIG · IOREDFOUR
I
ioredfour
storagejavascriptv1.4.1
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
const Lock = require('ioredfour');
import Lock from 'ioredfour';
Package is CommonJS only; ESM import will fail. Use require().
default
const Lock = require('ioredfour').default || require('ioredfour');
const Lock = require('ioredfour').default;
No default export; module.exports is the Lock class itself.
Lock
import pkg from 'ioredfour'; const Lock = pkg.default || pkg;
import { Lock } from 'ioredfour';
No named export; must import default and handle ambiguous default.

Demonstrates acquiring and releasing a distributed lock with ioredfour.

const Lock = require('ioredfour'); (async () => { const lock = new Lock({ redis: { host: '127.0.0.1', port: 6379 }, namespace: 'mylock', minReplications: 1, replicationTimeout: 500 }); const id = Math.random().toString(); const acquired = await lock.acquireLock(id, 60000); if (acquired.success) { console.log('Lock acquired'); await lock.releaseLock(acquired); console.log('Lock released'); } else { console.log('Lock not acquired'); } lock.quit(); })().catch(console.error);
Debug
Known issues
gotchaThe module creates a separate Redis connection by default. To reuse an existing ioredis instance, pass it directly via the 'redis' option.
fix
Pass an existing ioredis instance: new Lock({ redis: existingClient, namespace: '...' })
affects: >=1.0.0
gotchaWhen using Redis Cluster, sharded pub/sub (SSUBSCRIBE/SPUBLISH) is used for release notifications, requiring Redis 7+. If unavailable, initialization fails.
fix
Ensure Redis server version >=7.0 when using Cluster mode, or avoid using waitAcquireLock.
affects: >=1.0.0
gotchareplicationTimeout must be <= (lock TTL) / 1.5. If set too high, lock logic may break.
fix
Set replicationTimeout <= 0.66 * lock TTL in milliseconds.
affects: >=1.0.0
gotchaThe 'redis' option can be a connection string, an object (ioredis options), or an existing ioredis instance. Passing a string will create a new connection.
fix
For an existing instance, pass the instance directly as the 'redis' option.
affects: >=1.0.0
gotchaAfter releasing the lock, call lock.quit() to close the underlying Redis connection(s).
fix
Always call lock.quit() when you are done using the lock.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Module "ioredfour" does not have a default export
Using ES module import (import) on a CommonJS-only package.
fix
Use const Lock = require('ioredfour');
TypeError: lock.quit is not a function
Trying to call quit() on an object that is not the lock instance (e.g., a lock response object).
fix
Call quit() on the Lock instance, e.g., const lock = new Lock(...); ...; lock.quit();
Redis Cluster: ERR unknown command 'SSUBSCRIBE'
Redis version <7.0 does not support sharded pub/sub required for Cluster mode.
fix
Upgrade Redis to 7.0+ or avoid using waitAcquireLock.
LockError: Lock not acquired after wait
waitAcquireLock timed out or lock was never released.
fix
Ensure lock TTL is sufficient and release is called eventually.
Upgrade
Version history
1.4.1latest on npm
Audit
Dependencies
ioredisrequiredRequired for Redis and Redis Cluster connections. Must be installed separately (peer dependency).
Agent activity
22 hits · last 30 days
node
22
Resources
ioredfour — npm install ioredfour · libregistry