https://github.com/yourtion/node-elock
Easy use distributed redis lock implementation
https://github.com/yourtion/node-elock
distributed distributed-lock node-lock redis redis-lock
Last synced: about 1 month ago
JSON representation
Easy use distributed redis lock implementation
- Host: GitHub
- URL: https://github.com/yourtion/node-elock
- Owner: yourtion
- License: mit
- Created: 2018-01-06T03:17:03.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2020-05-30T19:53:19.000Z (about 6 years ago)
- Last Synced: 2025-07-12T02:35:34.743Z (12 months ago)
- Topics: distributed, distributed-lock, node-lock, redis, redis-lock
- Language: TypeScript
- Homepage: https://npmjs.org/package/elock
- Size: 255 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# node-elock
[](https://greenkeeper.io/)
Easy use distributed redis lock implementation
## Installation
```bash
npm install elock --save
```
## Usage
```javascript
// Init redis client
const Redis = require('ioredis');
const redisClient = new Redis();
// Init ELock
const ELock = require('elock');
const lock = new ELock({ redis: redisClient });
// Acquire Lock
lock.acquire('key').then(() => {
// do someting when get lock
// release after done
return lock.release('key')
}).catch((err) => {
// err when can't get lock
})
// Get lock
lock.get('key').then((res) => {
if(res === null) return '' // null is get lock fail
// do someting when get lock
})
// Check is Locked
lock.locked('key').then((locked) => {
// locked is a boolean
})
```