See this blog post for more information.
This module produces consistent output with python-hash_ring==1.2.
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
varHashRing=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:8080varring=newHashRing({"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:8080See ./test/test_distribution.js for another example: node test/test_distribution.js
To run the tests:
$ make test
MIT License
Brian Noguchi
Krzysztof Dorosz (compatibility with the python-hash_ring module)