warlock
Battle-hardened distributed locking using redis.
Requirements
- node-redis compatible with
v0.10
- Redis
v2.6
or above
Install
npm install node-redis-warlock
Usage
var Warlock = require('node-redis-warlock');
var redis = require('redis');
var redis = redis.createClient();
var warlock = Warlock(redis);
var key = 'test-lock';
var ttl = 10000;
warlock.lock(key, ttl, function(err, unlock){
if (err) {
return;
}
if (typeof unlock === 'function') {
unlock();
} else {
}
});
ProTips
- Warlock uses Lua scripting to achieve transactional locking on Redis
v2.6.0
upwards. If you're running Redis v2.6.12
or above you could use the additional PX and NX arguments for the SET operation as an alternative. - Read my Distributed locks using Redis article and Redis' author's A proposal for more reliable locks using Redis to learn more about the theory of distributed locks using Redis.