Distributed locking mechanism with lock names, retries, timeouts and keep-alive.
var redlock = require('redlock');
var getLock = redlock({
client : redisClient,
prefix : 'lock:',
timeout : 120,
});
getLock('mylock', function(err, lock) {
// if there's been a bad error, get out of here
if (err) throw err;
// if we didn't get the lock, just return
if ( !lock ) return;
doSomethingInvolvingAsyn(function(err) {
// we've now finished with the lock
lock.release();
});
});- client
- prefix (default: '')
- timeout (default: 60)
- name (required)
- timeout (optional)
- callback (required)
If you provide a timeout, it will be
Written by Andrew Chilton - Blog - Twitter.
(Ends)