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 ioredfourNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates acquiring and releasing a distributed lock with ioredfour.
Pass an existing ioredis instance: new Lock({ redis: existingClient, namespace: '...' })Ensure Redis server version >=7.0 when using Cluster mode, or avoid using waitAcquireLock.
Set replicationTimeout <= 0.66 * lock TTL in milliseconds.
For an existing instance, pass the instance directly as the 'redis' option.
Always call lock.quit() when you are done using the lock.
Use const Lock = require('ioredfour');Call quit() on the Lock instance, e.g., const lock = new Lock(...); ...; lock.quit();
Upgrade Redis to 7.0+ or avoid using waitAcquireLock.
Ensure lock TTL is sufficient and release is called eventually.