$ npm install locker-redis
$ npm install ioredis
var RedisLocker = require('locker-redis');
var LockerTimeoutError = require('locker-redis').LockerTimeoutError;
RedisLocker class
var lockerName = 'user:100:account';
var options = {};
var redisLocker = new RedisLocker(lockerName, options);
Acquire redisLocker retry some times.If timeout then throw error.
redisLocker.acquire(function (err, release) {
if (err) {
return callback(new Error());
}
// release(); You can call release function here to exec redis locker release.
callback(null);
});
Release this redisLocker
redisLocker.release();