# egg-redis-redlock

> a redis lock for egg web framework

Latest version **1.0.0** (published 2021-11-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install egg-redis-redlock
pnpm add egg-redis-redlock
yarn add egg-redis-redlock
bun add egg-redis-redlock
```

## 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.0 |
| Published | 2021-11-21 |
| First published | 2021-11-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=8.0.0 |
| Dependencies | 2 |
| Unpacked size | 7.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | kemin |
| Maintainers | uview |
| Keywords | egg, eggPlugin, egg-plugin |

## Links

- npm: https://www.npmjs.com/package/egg-redis-redlock
- Repository: https://github.com/keminshu/egg-rds-lock
- Homepage: https://github.com/keminshu/egg-rds-lock#readme
- Issues: https://github.com/keminshu/egg/issues
- npm.io page: https://npm.io/package/egg-redis-redlock

## Dependencies (2)

- [ioredis](https://npm.io/package/ioredis.md) ^4.5.1
- [redlock](https://npm.io/package/redlock.md) ^3.1.2

## Recent versions

- 1.0.0 (latest) — 2021-11-21

## README

# egg-rds-lock

[![NPM version][npm-image]][npm-url]
[![build status][travis-image]][travis-url]
[![Test coverage][codecov-image]][codecov-url]
[![David deps][david-image]][david-url]
[![Known Vulnerabilities][snyk-image]][snyk-url]
[![npm download][download-image]][download-url]

[npm-image]: https://img.shields.io/npm/v/egg-rds-lock.svg?style=flat-square
[npm-url]: https://npmjs.org/package/egg-rds-lock
[travis-image]: https://img.shields.io/travis/eggjs/egg-rds-lock.svg?style=flat-square
[travis-url]: https://travis-ci.org/eggjs/egg-rds-lock
[codecov-image]: https://img.shields.io/codecov/c/github/eggjs/egg-rds-lock.svg?style=flat-square
[codecov-url]: https://codecov.io/github/eggjs/egg-rds-lock?branch=master
[david-image]: https://img.shields.io/david/eggjs/egg-rds-lock.svg?style=flat-square
[david-url]: https://david-dm.org/eggjs/egg-rds-lock
[snyk-image]: https://snyk.io/test/npm/egg-rds-lock/badge.svg?style=flat-square
[snyk-url]: https://snyk.io/test/npm/egg-rds-lock
[download-image]: https://img.shields.io/npm/dm/egg-rds-lock.svg?style=flat-square
[download-url]: https://npmjs.org/package/egg-rds-lock

<!--
Description here.
-->

## Install

```bash
$ npm i egg-rds-lock --save
```

## Usage

```js
// {app_root}/config/plugin.js
exports.rdsLock = {
  enable: true,
  package: 'egg-rds-lock',
};
```

## Configuration

```js
// {app_root}/config/config.default.js
exports.rdsLock = {
    // DO NOT modify, or invoke a bad affect for the live lock, 
    // @see <https://github.com/mike-marcacci/node-redlock#configuration>
    client:{
        nodes:[
        {
            port: 6379,
            host: '127.0.0.1',
            password: '',
            db: 2,
        }]
    },
    options:{
		// the expected clock drift; for more details
		// see http://redis.io/topics/distlock
		driftFactor: 0.01, // time in ms
		// the max number of times Redlock will attempt
		// to lock a resource before erroring
		retryCount:  5,
		// the time in ms between attempts
		retryDelay:  100, // time in ms
		// the max time in ms randomly added to retries
		// to improve performance under high contention
		// see https://www.awsarchitectureblog.com/2015/03/backoff.html
		retryJitter:  200 // time in ms
    },
    app:true,
    agent:false // not enable on agent process
};
```

see [config/config.default.js](config/config.default.js) for more detail.

## Example
```js
const {Controller} = require('egg');
class Ctrl extends Controller {
  async test() {
    const {app,ctx} = this;
    let resource = "lock:test";
    try{
      let lock = await app.rdsLock.lock(resource,20*1000);
      // todo something
      await lock.unlock();
    } catch (e) {
      ctx.body = "unavailable";
      return;
    }
    ctx.body = "available";
  }
}
```
<!-- example here -->

## Questions & Suggestions

Please open an issue [here](https://github.com/eggjs/egg/issues).

## License

[MIT](LICENSE)

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