# node-redis-lock

> Node.js Redis locking tool.

Latest version **1.0.1** (published 2016-11-24) · BSD-2-Clause license · 0 weekly downloads

## Install

```sh
npm install node-redis-lock
pnpm add node-redis-lock
yarn add node-redis-lock
bun add node-redis-lock
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2016-11-24 |
| First published | 2014-05-23 |
| Weekly downloads | 0 |
| License | BSD-2-Clause |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= v0.8.0 |
| Dependencies | 3 |
| Known vulnerabilities | 0 (+2 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 9 |
| Author | Philmod |
| Maintainers | philmod, livefyre |
| Keywords | redis, lock, locking |

## Links

- npm: https://www.npmjs.com/package/node-redis-lock
- Repository: https://github.com/Philmod/node-redis-lock
- Homepage: https://github.com/Philmod/node-redis-lock.git
- Issues: https://github.com/Philmod/node-redis-lock/issues
- npm.io page: https://npm.io/package/node-redis-lock

## Dependencies (3)

- [uuid](https://npm.io/package/uuid.md) ^3.0.0
- [redis](https://npm.io/package/redis.md) ^2.5.3
- [redis-scripto](https://npm.io/package/redis-scripto.md) 0.1.3

## Alternatives

- [memory-cache](https://npm.io/package/memory-cache.md) — 795.0K weekly downloads
- [@httptoolkit/proxy-agent](https://npm.io/package/@httptoolkit/proxy-agent.md) — 11.2K weekly downloads
- [express-cache-controller](https://npm.io/package/express-cache-controller.md) — 5.3K weekly downloads
- [http-cache-middleware](https://npm.io/package/http-cache-middleware.md) — 4.5K weekly downloads
- [cache2](https://npm.io/package/cache2.md) — 1.5K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2016-11-24
- 1.0.0 — 2016-04-01
- 0.1.1 — 2014-07-14
- 0.1.0 — 2014-07-14
- 0.0.7 — 2014-05-28
- 0.0.6 — 2014-05-27
- 0.0.4 — 2014-05-23
- 0.0.2 — 2014-05-23

## 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 &lt;philippe.modard@gmail.com&gt;

---
_Source: https://npm.io/package/node-redis-lock · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
