New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

redlock-leader

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redlock-leader

A Leader selection module using redlock distributed lock algorithm

latest
Source
npmnpm
Version
1.0.2
Version published
Weekly downloads
5
Maintainers
1
Weekly downloads
 
Created
Source

Redlock Leader

Leader election by Redlock Distributed Lock Manager algorithm.

Install

npm install redlock-leader

Usage

const RedlockLeader = require('redlock-leader');
const client = require('redis').createClient({
  host: process.env.REDIS_HOST || '127.0.0.1',
  port: 6379,
  enable_offline_queue: false,
  //password: '',
  //db: 1,
  retry_strategy: function (options) {
    return Math.min(options.attempt * 100, 3000);
  }
});

const leader = new RedlockLeader({
  clients: [client], {
    ttl: 10000,
    wait: 1000,
    key: 'my-leader-key'
}});

leader.on('elected', () => console.log(`${process.pid} ${new Date()} Instance is elected as leader.`));
leader.on('revoked', () => console.log(`${process.pid} ${new Date()} Instance is no longer the leader.`));
leader.on('extended', () => console.log(`${process.pid} ${new Date()} Leadership status of instance is extended.
`));
leader.on('error', (e) => console.log(`${process.pid} ${new Date()} ERROR`, e));

leader.start();

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 milliseconds
    • key 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

How it works

https://redis.io/topics/distlock

Keywords

redlock

FAQs

Package last updated on 26 Oct 2020

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