idserver
v0.2.1
Published
A sequential ID generation server
Downloads
6
Maintainers
Readme
idserver: A sequential ID generation server
idserver
is a node.js centralized sequential ID server for helping distributed applications getting unique and sequential IDs for their entities.
Installing
npm install idserver
Running a server
Running an idserver daemon:
node node_modules/idserver/bin/server.js
Server options:
The default server (bin/server.js) shipped with idserver has no configurations - everything is on default.
Server()
constructor supports the following options:
port
: TCP port number where the server should listen on; Defaults to1970
;address
: The network address where the server should listen on; Defaults to127.0.0.1
;journaling
: Enables or disables the journaling supports; Defaults totrue
;journalFile
: File path for storing the journaling data; Defaults to/tmp/idserver.journal
;dataFile
: File path to be used for storing data (when using the internal storage system); Defaults to/tmp/idserver.data
;commitInterval
: The interval of time between commits (or sets); Defaults to1000
ms;getter
: Function to be used for getting the last ID for a key. The function arguments are(key,callback)
. Defaults to an internal dumb method. If agetter
and asetter
or agetter
and acommitter
are specified, the internal storage system is disabled;setter
: Function to be used for storing the last ID for a key. The function arguments are(key,value,callback)
. Defaults to an internal dumb method; If agetter
and asetter
or agetter
and acommitter
are specified, the internal storage system is disabled;committer
: The same assetter
but for storing a set of keys and values at the same time. If acommitter
function is specified,setter
is not used. Defaults to an internal commit function; If agetter
and asetter
or agetter
and acommitter
are specified, the internal storage system is disabled;idPattern
: The pattern for the resulting IDs ornull
. Something like 'CLIENT-%%%-###' where '#' means a digit and '%' a letter between 'A' and 'Z'; Defaults tonull
- meaning a regular integer (between 1 and the biggest supported integer);keyOptions
: An object containing the options to be used for a specific key; The supported options are:idPattern
;DEBUG
: Activates or deactivates the debugging mode; Defaults tofalse
.
Running a client and asking for ids:
var
IDClient = require('idserver').Client,
client = new IDClient({host: "127.0.0.1"});
client.ask("x",10,function(err,ids){
if ( err ) {
console.log("Error getting IDs: ",err);
throw err;
}
console.log("Got IDs: ",ids);
});
Client()
constructor supports the following options:
host
: The network address of the server; Defaults to127.0.0.1
;port
: The TCP port number of the server; Defaults to1970
;MAXRETRIES
: Maximum number of connect retries; Defaults tonull
- meaning infinite number of retries;DEBUG
: Activates or deactivates de debugging mode; Defaults tofalse
.
A Client
instance supports the following methods:
ask('KEY',NUMBER_OF_IDS,callback)
- Ask for a specific number of IDs (optional - defaults to 1) for a key (required).last('KEY',callback)
- Get the last ID for a key (required).
Bugs and stuff
Mail me or make a Github issue request.