redis-sp (Synchronization Primitives) is a TypeScript library providing distributed mutex and counting semaphore implementations based on the Redlock algorithm. Version 1.3.2, released in 2021, is the latest stable release with no active development observed. It relies on ioredis clients and uses Redis Lua scripts for atomicity, avoiding race conditions common in other implementations. Differentiates from alternatives like 'redlock' by offering both mutex and semaphore primitives with TypeScript support.
npm install redis-spNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates creating a RedisMutex, acquiring a lock, executing critical code, and releasing the lock with proper error handling.
Wrap lock() in try-catch and handle LockAcquisitionError explicitly; do not assume immediate success.
Consider alternative actively maintained libraries like 'redlock' for Redlock algorithm.
Ensure each critical section uses a distinct, namespaced resource identifier.
Always pass clients as an array: new RedisMutex([client], key).
Use ioredis client only; the library is not compatible with 'redis' v4+ client.
Increase retry options or ensure previous lock is released; use tryLock() with timeout.
Update to v1.3.2 and use import { RedisMutex } from 'redis-sp'.