Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
A Consistent Hashing C++ add-on for node.js
C++ C JavaScript
Branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
src Layout simplification (move wscript to root level, remove lib folder)…
test Converted test_distribution.js to use expresso and should.js. Added M…
.gitignore Added node_modules to .gitignore
Makefile Converted test_distribution.js to use expresso and should.js. Added M…
README.md
index.js Fix reference to the build module following node 0.6x upgrade
package.json Update package.json
wscript Layout simplification (move wscript to root level, remove lib folder)…

README.md

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


See this blog post for more information.

Installation

Via npm:

npm install hash_ring

Via git:

git clone http://github.com/bnoguchi/node-hash-ring.git
cd node-hash-ring/src
node-waf configure build

Example

var HashRing = require("./lib/hash_ring");

// Create a cluster of 3 servers weighted so that 127.0.0.2:8080 stores twice as many 
// keys as 127.0.0.1:8080, and 127.0.0.3:8080 stores 4x as many keys as 127.0.0.1:8080
// and 2x as many keys as 127.0.0.2:8080
var ring = new HashRing({"127.0.0.1:8080": 1, "127.0.0.2:8080": 2, "127.0.0.3:8080":4});
console.log(ring.getNode("users:102") ); // Should be 127.0.0.3:8080

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

Tests

To run the tests:

$ make test

License

MIT License


Author

Brian Noguchi

Something went wrong with that request. Please try again.