Skip to content

Redis distributed lock across multiple instances/servers using setnx

License

Notifications You must be signed in to change notification settings

pierreinglebert/redis-lock

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

redis-lock

Redis distributed lock across multiple instances/servers using setnx

NPM version build status Test coverage

Requirements

- Redis 2.6.12

Install

npm install redis-locking

Examples

var lock = require('redis-locking')(redis);

lock.acquire('mykey', {ttl: 500})
.then(function() {
  //do something
})
.then(function() {
  return lock.release('mykey');
})

API

Both methods return promises.

acquire (key, options)

Take the lock and avoid others to take it.

`key` is a string key identifying the lock

options

`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 (key)

Release the lock for others.

`key` string identifying the lock

isLocked (key)

Tells if the lock is taken.

`key` string identifying the lock

returns `true` or `false`

renew (key, ttl)

`key` string identifying the lock

`ttl` new lock time-to-live in ms

License

MIT

About

Redis distributed lock across multiple instances/servers using setnx

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages