idserver v0.2.1
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 idserverRunning a server
Running an idserver daemon:
node node_modules/idserver/bin/server.jsServer 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 to1000ms;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 agetterand asetteror agetterand acommitterare 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 agetterand asetteror agetterand acommitterare specified, the internal storage system is disabled;committer: The same assetterbut for storing a set of keys and values at the same time. If acommitterfunction is specified,setteris not used. Defaults to an internal commit function; If agetterand asetteror agetterand acommitterare 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.