Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/philmod/node-redis-lock
Locks in Redis.
https://github.com/philmod/node-redis-lock
Last synced: 3 months ago
JSON representation
Locks in Redis.
- Host: GitHub
- URL: https://github.com/philmod/node-redis-lock
- Owner: Philmod
- Created: 2014-05-23T17:24:02.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2016-11-24T16:34:39.000Z (about 8 years ago)
- Last Synced: 2024-10-06T20:05:44.124Z (3 months ago)
- Language: JavaScript
- Size: 15.6 KB
- Stars: 9
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# node-redis-lock
Node.js redis locking system.
## Installation
$ npm install node-redis-lock
## Use
```js
const Lock = require('node-redis-lock');
const redis = require('redis');
const client = redis.createClient();// Instantiate a lock.
let lock = new Lock({namespace: 'locking'}, client);// Acquire a lock.
const key = 'job1';
const value = ['owned-by-',require('os').hostname()].join('');
const ttl = 1; // seconds
lock.acquire(key, ttl, value, (e, r) => {
// r === true;
});// Renew a lock.
// It fails if the value is different.
lock.renew(key, ttl, value, (e, r) => {
// r === true;
});// Release a lock.
// The value has to be passed to ensure another host doesn't release it.
lock.release(key, value, (e, r) => {
//
});// Does a lock exist?
lock.isLocked(key, (e, r) => {
// Lock if r exists (this is the value of the lock)
});
```## Tests
$ npm test
## Author
Philmod <[email protected]>