# io-locks

> Distributed Locks using Redis

Latest version **1.0.2** (published 2021-03-24) · ISC license · 0 weekly downloads

## Install

```sh
npm install io-locks
pnpm add io-locks
yarn add io-locks
bun add io-locks
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2021-03-24 |
| First published | 2021-03-22 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=10.0.0 |
| Dependencies | 2 |
| Unpacked size | 5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Amit Kumawat |
| Maintainers | amitkumawat |
| Keywords | locks, redis, ioredis |

## Links

- npm: https://www.npmjs.com/package/io-locks
- npm.io page: https://npm.io/package/io-locks

## Dependencies (2)

- [events](https://npm.io/package/events.md) ^3.3.0
- [ioredis](https://npm.io/package/ioredis.md) ^4.24.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.2 (latest) — 2021-03-24
- 1.0.1 — 2021-03-22
- 1.0.0 — 2021-03-22

## README

# io-locks
 
## How to use
 
```js
const IoLock = require('io-locks');
const ioLock = IoLock({ host: 'localhost', port: 6379 });
```
 
## API
 
### IoLock(uri[, opts])
 
`uri` is a string like `localhost:6379` where your redis server
is located. For a list of options see below.
 
### IoLock(opts)
 
The following options are allowed:
 
- `key`: the name of the key to pub/sub events on as prefix (`io-timers`)
- `host`: host to connect to redis on (`localhost`)
- `port`: port to connect to redis on (`6379`)
- `client`: optional, the redis client
 
If you decide to supply `client`, make sure you use
[node_redis](https://github.com/mranney/node_redis) as a client or one
with an equivalent API.
 
### IoLock#setLock(resourceId: String, duration: Number)
 
Set Lock with given time duration[in Seconds]
```js
ioLock.setLock("resourceId", 10);
```
 
### IoLock#isLock(resourceId: String)
 
Check resource acquired lock or not.
 
```js
let isLocked = await ioLock.isLock("resourceId");
```
 
### IoLock#releaseLock(resourceId: String)
 
Stop timer
 
```js
iolock.releaseLock("resourceId");
```
 
## Client error handling
 
Error Handling
 
```js
iolock.locks.on("error", function(err){
    //Handle Error
})
```
 
## License
 
ISC

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