Skip to content

node-id-gen - A sequence (auto-increment) id generation service using nodejs + redis + lua

License

Notifications You must be signed in to change notification settings

dsidman-aeg/node-id-gen

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

node-id-gen

node-id-gen - A sequence id generation services using nodejs + redis + lua

Installation

$ npm install --save node-id-gen ⏎

Usage

var nodeIdGen = require('node-id-gen');
var redisClient = require('redis').createClient();

nodeIdGen.init(redisClient);

//create a auto increment sequence for userId
nodeIdGen.createSequence({'name': 'userId'});

//next method which is promise and return the sequence
nodeIdGen.next('userId').then(function(seq) {
	console.log(seq);  // 1
}).catch(function(err) {
	console.log(err);
});

Options

We have few options with init() method

nodeIdGen.init(redisClient, {
	'retryTimes': 10,  //default 100
	'retryDelay': 500  //default 500 (in milliseconds)
});

Options while creating a new sequence

nodeIdGen.createSequence({
	'name': 'userId',
	'startSequence': 1000, //default its 0 which 1 if call next() sequence
	'maxSequence': 999999 //default its 999999999 after which next() method shall throw error
});

Author

Writen by Bikash Kumar Sharma - Site

License

Copyright (c) 2017 Bikash Kumar Sharma

About

node-id-gen - A sequence (auto-increment) id generation service using nodejs + redis + lua

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 84.6%
  • Lua 15.4%