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
}
],
hash: 'md5'
});
console.log(ring.get('some key'));
api
add member
adds a new member
ring.add('member4');
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');
check if a member exists
ring.exists('member1')
get member count
ring.length;
author
Ekin Koc
license
MIT