New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

consistent

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

consistent

Consistent hashing for Node.JS

  • 1.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
134
increased by3.08%
Maintainers
1
Weekly downloads
 
Created
Source

consistent

Consistent hashing module for Node.JS

installation

npm install consistent

usage

var consistent = require('consistent');

var ring = consistent({
  members: [
    "member1",
    "member2",
    {
      key: "member3",
      weight: 1.5 // optional, default weight is 1
    }
  ],
  hash: 'md5' // can use 'md5' or 'murmurhash'
});

console.log(ring.get('some key'));
// outputs member1 or member2 or member3

api

add member

adds a new member

ring.add('member4');
// or
ring.add({
  key: "member4",
  weight: 3
})

remove member

removes a member

ring.remove("member2")

replace member

this preserves the hash slots of old member, if you want to recalculate hashes for the new member, just remove the old one and add the new one.

ring.replace('member1', 'member5');

get member for hash slot

ring.get('some key');
ring.getCached('some key'); //use lru cache

check if a member exists

ring.exists('member1') // returns true if a member has been added with name member1

get member count

ring.length; // returns number of members within the ring

author

Ekin Koc

license

MIT

Keywords

FAQs

Package last updated on 05 Jan 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