simple-redis-mutex is a lightweight distributed mutex lock implementation using Redis, based on the SETNX + EXPIRE pattern described in Redis docs. Version 3.0.0 ships TypeScript types, supports ESM and CJS, and relies on Redis >=5.0.0 as a peer dependency. Unlike the more complex Redlock algorithm, this library focuses on simplicity and uses Redis Pub/Sub for immediate lock release notification, with manual polling as a fallback. It offers two lock acquisition methods: blocking `lock` and non-blocking `tryLock`, both returning a release function with an optional fencing token. The package is actively maintained and suitable for Node.js >=8.2.1.
npm install simple-redis-mutexNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates acquiring a distributed mutex lock via `lock` with a Redis client, performing critical work, and releasing the lock.
Upgrade redis to >=5.0.0 as a peer dependency.
Always `await release()` or return the promise.
Wrap lock acquisition in try/catch or handle promise rejections.
Replace `failAfter` with explicit `timeout` and `pollingInterval` options.
Use `release().then(() => { ... })` or `await release();`.Set `"type": "module"` in package.json or use CommonJS require: `const { lock } = require('simple-redis-mutex');`Ensure you have redis >=5.0.0 installed and use `import { createClient } from 'redis';`Upgrade Redis server to version 2.6.12 or later.
Use correct import: `import { lock } from 'simple-redis-mutex';`