Permalink
Browse files

[doc] Upgrade the docs to be more readable

[minor] Updated the CHANGELOG
[minor] Prepping the package.json
  • Loading branch information...
1 parent aa1a013 commit fbb0b5bce7da15d8427ed733bc0bfa193a215e17 @3rd-Eden committed Feb 24, 2013
Showing with 72 additions and 22 deletions.
  1. +4 −0 CHANGELOG
  2. +34 −1 README.md
  3. +12 −21 package.json
  4. +22 −0 tests/api.test.js
View
@@ -1,3 +1,7 @@
+Feb 24, 2013
+- Refactored the whole driver, these changes are incompatible with the 0.0.x
+ releases as they have changed the distriubtion of keys.
+
Jan 11, 2013
- Added LRU caching instead of a plain object for caching, this prevents memory
leaks
View
@@ -101,13 +101,24 @@ custom hasher. But do note that the hashValue will be calculated on the result.
frequent key lookups, you can customize the amount of keys that need to be
cached. It defaults to 5000.
-### API
+### API's Table of Contents
+
+- [HashRing.continuum()](#hashringcontinuum)
+- [HashRing.get()](#hashringgetkey)
+- [HashRing.range()](#hashringrangekey-size-unique)
+- [HashRing.swap()](#hashringswapfrom-to)
+- [HashRing.add()](#hashringaddserver)
+- [HashRing.remove()](#hashringremoveserver)
+- [HashRing.reset()](#hashringreset)
+- [HashRing.end()](#hashringend)
#### HashRing.continuum()
Generates the continuum of server a.k.a the Hash Ring based on their weights and
virtual nodes assigned.
+---
+
#### HashRing.get(**key**)
Find the correct node for the key which is closest to the point after what the
@@ -117,6 +128,8 @@ given key hashes to.
**returns:** The matching server address.
+---
+
#### HashRing.range(**key**, **size**, **unique**)
Returns a range of servers. Could be useful for replication.
@@ -128,6 +141,8 @@ Returns a range of servers. Could be useful for replication.
**returns:** The array of servers that we found.
+---
+
#### HashRing.swap(**from*, **to**)
Hotswap identical servers with each other. This doesn't require the cache to be
@@ -139,27 +154,37 @@ create a different distribution.
- **from** String, The server that needs to be replaced
- **to** String. The server that replaces the server
+---
+
#### HashRing.add(**server**)
Add a new server to ring without having to re-initialize the hashring. It
accepts the same arguments as you can use in the constructor.
- **server** Server that need to be added to the ring.
+---
+
#### HashRing.remove(**server**)
Remove a server from the hash ring.
- **server** Server that need to be removed from the ring.
+---
+
#### HashRing.reset()
Reset the HashRing and clean up it's references.
+---
+
### HashRing.end()
Reset's the HashRing and closes the ring.
+---
+
#### HashRing.find(**hashValue**) (private)
Finds the correct position of the given hashValue in the hashring.
@@ -168,6 +193,8 @@ Finds the correct position of the given hashValue in the hashring.
**returns:** Index of the value in the ring.
+---
+
#### HashRing.hash(**key**) (private)
Generates the hash for the key.
@@ -176,6 +203,8 @@ Generates the hash for the key.
**returns:** The hashed valued.
+---
+
#### HashRing.digest(**key**) (private)
Digest hash so we can make a numeric representation from the hash. So it can be
@@ -185,6 +214,8 @@ fed in to our hashValue.
**returns:** An array of charCodeAt(0) converted chars.
+---
+
#### HashRing.hashValue(**key**) (private)
Get the hashed value of the given key, it does the digesting, hashing yo.
@@ -193,6 +224,8 @@ Get the hashed value of the given key, it does the digesting, hashing yo.
**returns:** The hash value of the key.
+---
+
#### HashRing.points(**servers**)
Returns the points per server.
View
@@ -1,36 +1,27 @@
{
"name": "hashring",
- "version": "0.0.8",
+ "version": "1.0.0",
"author": "Arnout Kazemier",
- "description": "A pure JavaScript hash ring based on libketama",
+ "description": "A consistent hashring compatible with ketama hashing and python's hash_ring",
"main": "./index.js",
"keywords": [
"hashring",
"hash ring",
"hashing",
+ "hashvalue",
+ "ketama",
+ "hash_ring",
"hash",
"consistent hashing",
"libketama"
],
- "maintainers": [
- {
- "name": "Arnout Kazemier",
- "email": "info@3rd-Eden.com",
- "web": "http://www.3rd-Eden.com"
- }
- ],
- "licenses": [
- {
- "type": "MIT",
- "url": "http://github.com/3rd-Eden/node-hashring/blob/master/LICENSE"
- }
- ],
- "repositories": [
- {
- "type": "git",
- "url": "http://github.com/3rd-Eden/node-hashring.git"
- }
- ],
+ "license": "MIT",
+ "bugs": "http://github.com/3rd-Eden/node-hashring/issues",
+ "homepage": "http://github.com/3rd-Eden/node-hashring/",
+ "repository": {
+ "type": "git",
+ "url": "http://github.com/3rd-Eden/node-hashring.git"
+ },
"dependencies": {
"connection-parse": "0.0.x",
"simple-lru-cache": "0.0.x"
View
@@ -216,5 +216,27 @@ describe('HashRing', function () {
ring.ring.should.have.length(0);
});
});
+
+ describe('#range', function () {
+ it('returns 20 servers', function () {
+ var ring = new Hashring([
+ '192.168.0.102:11212'
+ , '192.168.0.103:11212'
+ , '192.168.0.104:11212'
+ ]);
+
+ ring.range('foo', 20, false).should.have.length(20);
+ });
+
+ it('returns 3 servers as we only want unique servers', function () {
+ var ring = new Hashring([
+ '192.168.0.102:11212'
+ , '192.168.0.103:11212'
+ , '192.168.0.104:11212'
+ ]);
+
+ ring.range('foo', 20, false).should.have.length(20);
+ });
+ });
});
});

0 comments on commit fbb0b5b

Please sign in to comment.