Leader election through Redlock
Inspired by redis-leader
- Redis 2.6.12
npm install redlock-coordinator
const Redis = require('io-redis');
const Leader = require('redlock-coordinator');
const coordinator = new Coordinator([
new Redis( /* ... */),
], { key: 'admin:coordinator:lock', logger: getLogger('coordinator') });
Create a new Coordinator
redis
is an array of redis object like node redis, ioredis or any other compatible redis library
key
redis key value, default: coordinator:redlock
logger
logger, default value: console
wait
Time between 2 tries getting elected (ms), default value: 1000
ttl
Lock time to live in milliseconds (will be automatically released after that time), default value: 10000
renew
Renew time to expand expiration time in milliseconds, default value: 5000
redlock
: options for redlock, details can be confirm on redlock
Elect coordinator
Stop election and resign coordinator if I am coordinator.
Tells if i got elected
elected
when your candidate become leader
resigned
when your leader got revoked from his leadership
error
when an error occurred, best is to exit your process
MIT