shared-lock
v0.0.3
Published
Shared local/distributed lock to reduce redis load and `write()` syscalls.
Downloads
7
Readme
shared-lock
Shared local/distributed lock to reduce redis load
and write()
syscalls.
Installation
$ npm install shared-lock
Example
var Lock = require('shared-lock');
var db = require('redis').createClient();
for (var i = 0; i < 25; i++) {
(function(i){
request('tobi:abby', function(){
console.log('finished tobi:abby %s', i);
});
})(i);
}
function request(key, fn) {
var lock = Lock({
key: 'marketo:' + key,
redis: db
});
lock.lock(function(err){
// faux work
setTimeout(function(){
lock.unlock(fn);
}, 500);
});
}
License
MIT