Redlock Leader
Leader election by Redlock Distributed Lock Manager algorithm.
Install
npm install redlock-leader
Usage
const RedlockLeader = ;const client =;const leader =clients: clientttl: 10000wait: 1000key: 'my-leader-key';leader;leader;leader;leader;leaderstart;
API
new RedlockLeader(clients, options)
Create a new leader selector.
clients
An array of redis client instances.options
An object holding the leader selection options.ttl
Lock time to live in milliseconds, defaults to 10000 milliseconds.wait
Time between 2 tries getting elected in milliseconds, defaults to 1000 millisecondskey
A string key identifying the lock, defaults to 'redlock-leader'
start()
Starts leader selection process.
stop()
Stops leader selection process.
isLeader
Indicates whether the instance is the leader or not.
Events
elected
when instance becomes the leader
revoked
when instance gets revoked from its leadership
extended
when instance's leadership ttl gets extended
error
when an error occurred at a redis client