Mutex and semaphore library implemented using basic Redis commands. Current stable version 0.3.7. Provides two synchronization primitives: mutex (exclusive lock with TTL) and semaphore (counting semaphore). Key differentiator: simple API using callbacks or promises, supports existing Redis connections, and includes wait/observe mechanisms with priority ordering. Unlike redlock or ioredis-based lock libraries, this uses basic Redis commands (SETNX, WATCH, etc.) without Lua scripting. The create methods reset the Redis key, which can lead to accidental context loss — a common footgun. Minimum Redis version 2.6.0+.
npm install redis-mutex-semaphoreNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows basic mutex usage: create factory from Redis client, create mutex with TTL, acquire lock, release lock.
Use getMutexClient(key) or getSemaphoreClient(key) after initial creation to avoid resetting keys.
Ensure semaphore key exists by first calling createSemaphoreClient, or handle ENOTFOUNDKEY error appropriately.
Store the mutexID returned from mutexClient.get() and use it exactly in the release call.
Use promise syntax: await mutexClient.get() instead of callback.
Ensure you call createSemaphoreClient first to initialize the key, or handle the error with proper fallback.
Verify you are using the exact mutexID returned by get() and that the mutex is still held by you.
Use: import factory from 'redis-mutex-semaphore' (ESM) or const factory = require('redis-mutex-semaphore') (CJS).