Socket
Socket
Sign inDemoInstall

redis-leader

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redis-leader

Leader election using redis


Version published
Maintainers
1
Created
Source

Redis leader

Leader election backed by Redis

Requirements

  • Redis 2.6.12

Install

npm install redis-leader

Examples


var Leader = require('redis-leader');

API

new Leader(redis, options)

Create a new Leader

redis is a string key identifying the lock

options

ttl Lock time to live in milliseconds (will be automatically released after that time)

wait Time between 2 tries getting elected (ms)

stop (callback)

Release the lock for others.

isLeader (callback)

Tells if he got elected.

callback(err, true/false)

Events

elected when your candidate become leader

revoked when your leader got revoked from his leadership

error when an error occurred, best is to exit your process

How it works

It uses setnx command to try to set a semaphore with the ttl given in options.

  • If it succeeds, it gets elected and will renew the semaphore every ttl/2 ms.
  • If it fails or get revoked, it tries to get elected every wait ms.

License

MIT

Keywords

FAQs

Package last updated on 27 Apr 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc