Registry / database / redis-leader

redis-leader

JSON →
library0.1.0jsnpmunverified

Leader election backed by Redis using SETNX command. Uses Redis 2.6.12+ atomic operations to elect a single leader among multiple candidates. Version 0.1.0. Low-level library with minimal dependencies but no active maintenance since 2016. Simpler alternative to node-redis-lock or node-zookeeper-based solutions.

npm install redis-leader
INSTALL
IMPORT
SIG · REDIS-LEADER
R
redis-leader
databasejavascriptv0.1.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Leader
const Leader = require('redis-leader');
import Leader from 'redis-leader';
CJS-only; ESM not supported.
Leader (ESM)
import Leader from 'redis-leader';
import { Leader } from 'redis-leader';
ESM is not supported by the package v0.1.0; CJS is the only option.
Leader (TypeScript)
const Leader = require('redis-leader');
import { Leader } from 'redis-leader';
No TypeScript definitions; use @types/redis or declare module.

Shows how to create a Redis client, instantiate Leader with options, handle events, start election, and stop.

const redis = require('redis'); const Leader = require('redis-leader'); const client = redis.createClient({ host: process.env.REDIS_HOST ?? 'localhost', port: process.env.REDIS_PORT ?? 6379, password: process.env.REDIS_PASSWORD ?? '' }); const leader = new Leader(client, { ttl: 10000, // lock TTL in ms wait: 1000 // poll interval in ms }); leader.on('elected', () => { console.log('I am the leader'); // do leader work }); leader.on('revoked', () => { console.log('Leadership revoked'); }); leader.on('error', (err) => { console.error('Leader error:', err); process.exit(1); }); leader.start(); // Later, stop leading leader.stop(() => { console.log('Stopped'); process.exit(); });
Debug
Known issues
deprecatedPackage is unmaintained since 2016; use modern alternatives like ioredis-based solutions or redis-lock.
fix
Consider using redis-semaphore or other actively maintained libraries.
affects: >=0.0.0
gotchaUses SETNX which is not Redis cluster safe; requires single Redis instance or properly configured cluster.
fix
Ensure you are connecting to a single Redis instance, not a cluster.
affects: >=0.0.0
gotchaThe 'start' method must be called explicitly after event handlers are attached, or you may miss the 'elected' event.
fix
Attach all event listeners before calling leader.start().
affects: >=0.0.0
Errors
Common errors & fixes
Error: Redis connection error
No Redis server running or incorrect connection config
fix
Start Redis server or check REDIS_HOST and REDIS_PORT environment variables.
TypeError: Leader is not a constructor
Using import or incorrect require
fix
Use const Leader = require('redis-leader');
Error: ECONNREFUSED 127.0.0.1:6379
Redis server not listening on default port
fix
Start Redis or set correct REDIS_HOST/REDIS_PORT.
Upgrade
Version history
0.1.0latest on npm
Audit
Dependencies
redisrequiredRequired for Redis client connection
Agent activity
9 hits · last 30 days
node
8
Resources
redis-leader — npm install redis-leader · libregistry