🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more

node-hashring

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-hashring

A consistent hashing ring with binary search

1.0.2
latest
Version published
Maintainers
1
Created

NodeJS HashRing

A consistent hashing ring with replicas for more even distribution (virtual nodes) and binary searching for best performance.

This hashring uses the MurmurHash algorithm which creates a 32-bit integer as opposed to using something like a 128-bit MD5. Which means, in comparison to an MD5 based hashring, this offers a lot more performance.

Usage

Install from npm

npm install node-hashing
// or
yarn add node-hashring

Create a hashring

This will create a hashring for two primary nodes, by default each node will be comprised of 80 virtual nodes.

const HashRing = require('node-hashring');
const hashRing = new HashRing([
  'server-address-1',
  'server-address-2',
]);

Get node from key

const serverAddress = hashRing.findNode('my-key');

Add a node

hashRing.addNode('server-address-2');

Remove a node

hashRing.removeNode('server-address-2');

FAQs

Package last updated on 11 Jan 2022

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