A TypeScript library for distributed Redis leader election with race-condition-free guarantees. Version 0.0.5 is the latest stable release; the project appears to be a fork of safe-redis-leader with TypeScript support, new events (elected/notElected), and tests verifying single-leader-at-a-time. Key differentiators include async/await API, removal of race conditions from the original redis-leader package, and Jest-based testing against a real Redis instance via Docker Compose. The library is small, focused, and suitable for Node.js applications needing reliable leader election without external dependencies beyond ioredis.
npm install ts-safe-redis-leaderNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Creates a Redis client and SafeRedisLeader instance then starts leader election with event listeners for elected/notElected.
Set lazyConnect: true and maxRetriesPerRequest: 0 in ioredis options.
Listen for 'elected' and 'notElected' events instead of custom event names.
Refer to ts-safe-redis-leader documentation for correct API.
Pass exactly (Redis client, ttl, interval, election key string).
Ensure ioredis is initialized with { lazyConnect: true } and call connect() before elect() if needed.Pass a non-empty string as the fourth argument to SafeRedisLeader constructor.
Import SafeRedisLeader as named export and ensure it is an instance of SafeRedisLeader.