A Consistent Hashing C++ add-on for node.js
C++ C JavaScript Python
Switch branches/tags
Latest commit 38b0069 Apr 21, 2017 @bnoguchi committed on GitHub Merge pull request #18 from jchip/master
Update for Node 4.x.x and up


node-hash-ring - Consistent Hashing C++ Add-on for node.js

See this blog post for more information.


Via npm:

$ npm install hash_ring

Via git:

$ git clone http://github.com/bnoguchi/node-hash-ring.git
$ cd node-hash-ring
$ npm run build


var HashRing = require("hash_ring");

// Create a cluster of 3 servers weighted so that stores twice as many 
// keys as, and stores 4x as many keys as
// and 2x as many keys as

var ring = new HashRing({"": 1, "": 2, "":4});
console.log(ring.getNode("users:102") ); // Should be

See ./test/test_distribution.js for another example:

$ node test/test_distribution.js

Key Hashing

By default, MD5 is used to hash keys. You can choose another hasher.

var HashRing = require("hash_ring");

var ring = new HashRing({"": 1, "": 2, "":4}, "murmur");

Supported hashers are:


To run the tests:

$ npm test


MIT License


Brian Noguchi