Giter Site home page Giter Site logo

node-idserver's Introduction

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 to 1970;

  • address : The network address where the server should listen on; Defaults to 127.0.0.1;

  • journaling : Enables or disables the journaling supports; Defaults to true;

  • 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 to 1000 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 a getter and a setter or a getter and a committer 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 a getter and a setter or a getter and a committer are specified, the internal storage system is disabled;

  • committer : The same as setter but for storing a set of keys and values at the same time. If a committer function is specified, setter is not used. Defaults to an internal commit function; If a getter and a setter or a getter and a committer are specified, the internal storage system is disabled;

  • idPattern : The pattern for the resulting IDs or null. Something like 'CLIENT-%%%-###' where '#' means a digit and '%' a letter between 'A' and 'Z'; Defaults to null - 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 to false.

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 to 127.0.0.1;

  • port : The TCP port number of the server; Defaults to 1970;

  • MAXRETRIES : Maximum number of connect retries; Defaults to null - meaning infinite number of retries;

  • DEBUG : Activates or deactivates de debugging mode; Defaults to false.

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.