Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8bf198e
commit c5ea467
Showing
5 changed files
with
213 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,3 +1,52 @@ | |||
addressbook | addressbook | ||
============ | ============ | ||
TBW | `addressbook` keeps tracking available node instances backed by Redis. | ||
|
|||
## Prerequisites | |||
Redis `>=2.6.4`. | |||
|
|||
On Mac with homebrew, | |||
```bash | |||
$ homebrew install redis | |||
$ redis-server | |||
``` | |||
|
|||
## Installation | |||
```bash | |||
$ npm install addressbook | |||
``` | |||
|
|||
## Version | |||
0.0.1 (pre-release) | |||
|
|||
# Usage | |||
```js | |||
var AB = require('addressbook'); | |||
var ab = new AB(); | |||
var myServicies = [{port: 3000, protocol: 'http'}, {port: 5004, protocol: 'dnode'}]; | |||
ab.update(myServicies, function(err, addressbook) { | |||
if (err) { | |||
throw err; | |||
} else { | |||
console.log(addressbook); | |||
} | |||
}); | |||
ab.pick(); // => return a randomly picked remote service | |||
``` | |||
|
|||
# API | |||
## ab.([port], [host], [options], [passowrd]) | |||
|
|||
## ab.update([myServicies], [callback]) | |||
|
|||
## ab.pick() | |||
|
|||
# Test | |||
```bash | |||
$ npm test | |||
``` | |||
|
|||
# License | |||
MIT | |||
|
|||
Copyright (c) 2012 Kazuyuki Tanimura |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,12 @@ | |||
var AB = require('addressbook'); | |||
var ab = new AB(); | |||
var myServicies = [{port: 3000, protocol: 'http'}, {port: 5004, protocol: 'dnode'}]; | |||
ab.update(myServicies, function(err, addressbook) { | |||
if (err) { | |||
throw err; | |||
} else { | |||
console.log(addressbook); | |||
} | |||
}); | |||
ab.pick(); // => return randomly picked remote service | |||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,10 +1,23 @@ | |||
{ | { | ||
"name": "addressbook" | "name": "addressbook" | ||
, "version": "0.0.1" | , "version": "0.0.1" | ||
, "private": true | , "description": "Addressbook keeps tracking available node instances backed by Redis." | ||
, "repository": { | |||
"type": "git", | |||
"url": "git://github.com/kazuyukitanimura/addressbook.git" | |||
} | |||
, "main" : "./index.js" | |||
, "keywords" : ["redis", "mdns"] | |||
, "dependencies": { | , "dependencies": { | ||
"redis" : ">= 0.8.2" | "redis" : ">= 0.8.2" | ||
} | } | ||
, "devDependencies": { | |||
"mocha" : ">= 1.7.0" | |||
} | |||
, "scripts" : { | |||
"test" : "mocha" | |||
} | |||
, "engine": "node >= 0.8.14" | , "engine": "node >= 0.8.14" | ||
, "license": "MIT" | , "license": "MIT" | ||
, "author": "kazuyukitanimura <kazuyukitanimura@gmail.com>" | |||
} | } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,46 @@ | |||
var assert = require("assert"); | |||
var Addressbook = require('../index'); | |||
var myServicies = [{ | |||
port: 3000, | |||
protocol: 'http' | |||
}, | |||
{ | |||
port: 5004, | |||
protocol: 'dnode' | |||
}]; | |||
|
|||
describe('Addressbook', function() { | |||
describe('#update()', function() { | |||
it('should return {ipaddress:[{port:portnumber}, ...], ...}', function(done) { | |||
var ab = Addressbook(); | |||
ab.update(function(err, addressbook) { | |||
assert(err instanceof Error); | |||
}); | |||
ab.update(myServicies, function(err, addressbook) { | |||
for (var key in addressbook) { | |||
var contacts = addressbook[key]; | |||
assert(Array.isArray(contacts)); | |||
for (var i = contacts.length; i--;) { | |||
var contact = contacts[i]; | |||
assert(contact.port); | |||
assert.deepEqual(typeof contact.port, 'number'); | |||
assert(contact.protocol); | |||
assert.deepEqual(typeof contact.protocol, 'string'); | |||
} | |||
} | |||
assert.deepEqual(ab.addressbook, addressbook); | |||
done(); | |||
}); | |||
}); | |||
}); | |||
describe('#pick(n)', function() { | |||
it('should return [{port:portnumber}, ...]', function(done) { | |||
var ab = Addressbook(); | |||
ab.update(function(err, addressbook) { | |||
assert(ab.pick().port); | |||
}); | |||
done(); | |||
}); | |||
}); | |||
}); | |||
|