Comparing version 2.0.1 to 2.0.2
13
index.js
@@ -418,2 +418,15 @@ 'use strict'; | ||
/** | ||
* Checks if a given server exists in the hash ring. | ||
* | ||
* @param {String} server Server for whose existence we're checking | ||
* @api public | ||
*/ | ||
HashRing.prototype.has = function add(server) { | ||
for (var i = 0; i < this.ring.length; i++) { | ||
if (this.ring[i].server === server) return true; | ||
} | ||
return false; | ||
}; | ||
/** | ||
* Reset the HashRing to clean up all references | ||
@@ -420,0 +433,0 @@ * |
{ | ||
"name": "hashring", | ||
"version": "2.0.1", | ||
"version": "2.0.2", | ||
"author": "Arnout Kazemier", | ||
@@ -5,0 +5,0 @@ "description": "A consistent hashring compatible with ketama hashing and python's hash_ring", |
@@ -211,2 +211,10 @@ # HashRing | ||
#### HashRing.has(**server**) | ||
Checks if a given server exists in the hash ring. | ||
- **server** Server for whose existence we're checking. | ||
--- | ||
#### HashRing.reset() | ||
@@ -213,0 +221,0 @@ |
@@ -220,2 +220,24 @@ "use strict"; | ||
describe('#has', function () { | ||
it('has a server', function () { | ||
var ring = new Hashring([ | ||
'192.168.0.102:11212' | ||
, '192.168.0.103:11212' | ||
, '192.168.0.104:11212' | ||
]); | ||
ring.has('192.168.0.102:11212').should.equal(true); | ||
}); | ||
it('does not have a server', function () { | ||
var ring = new Hashring([ | ||
'192.168.0.102:11212' | ||
, '192.168.0.103:11212' | ||
, '192.168.0.104:11212' | ||
]); | ||
ring.has('192.168.0.105:11212').should.equal(false); | ||
}); | ||
}); | ||
describe('#range', function () { | ||
@@ -222,0 +244,0 @@ it('returns 20 servers', function () { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2859090
1019
304