redlock-node
v2.1.4
Published
redis lock
Downloads
616
Readme
simple redis lock, support promise and callback.
usage
var RedLock = require('redlock-node');
var client = require('redis').createClient('port','host');
var redlock = new RedLock(client);
var lock;
`callback`:
//lock
/**
*params:
* @string: resource key
* @number: lock second
* @function: callback
*/
redlock.lock('test-resource-lock',3,function(err,lockInstance){
lock = lockInstance;
done(err);
});
//unlock
redlock.unlock(lock,function(err,data){
done(err);
});
//extend
redlock.extend(lock,2,function(err,data){
done(err);
});
`promise`:
redlock.lock('test-resource-lock-promise',3).done(
function(lock){
//todo
redlock.unlock(lock);
},
function(){
}
)
test
//test
npm test
//code coverage
npm run cov
code coverage
=============================== Coverage summary ===============================
Statements : 96.83% ( 183/189 )
Branches : 83.33% ( 30/36 )
Functions : 100% ( 77/77 )
Lines : 97.86% ( 183/187 )
================================================================================