Redis distributed lock across multiple instances/servers using setnx
- Redis 2.6.12
npm install redis-locking
var lock = require('redis-locking')(redis);
lock.acquire('mykey', {ttl: 500})
.then(function() {
//do something
})
.then(function() {
return lock.release('mykey');
})Both methods return promises.
Take the lock and avoid others to take it.
`key` is a string key identifying the lock
`ttl` Lock time to live in milliseconds (will be automatically released after that time)
`timeout` Time trying to get lock before (ms)
`wait` Time between 2 tries getting lock (ms)
Release the lock for others.
`key` string identifying the lock
Tells if the lock is taken.
`key` string identifying the lock
returns `true` or `false`
`key` string identifying the lock
`ttl` new lock time-to-live in ms
MIT