🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

egg-locker

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

egg-locker

[![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]][down

latest
Source
npmnpm
Version
2.0.0
Version published
Maintainers
1
Created
Source

egg-locker

NPM version build status Test coverage David deps Known Vulnerabilities npm download

Install

$ npm i egg-locker --save

Usage

// {app_root}/config/plugin.js
exports.locker = {
  enable: true,
  package: 'egg-locker',
};

Configuration

// {app_root}/config/config.default.js
exports.locker = {
    //redisName: 'lock',//egg-redis的实例名称,多实例的时候需要配置
    errorMessage: '系统繁忙,请稍后再试',
    maxListenerCount: 2000,
    keyPrefix:'lk:'
};

see config/config.default.js for more detail.

Example

// app/controller/index.js
const BaseController = require('egg').Controller

class Controller extends BaseController {
    async home(){
        const orderid = 'xxxxx'
        //并发控制的方法,相同的orderid只有一个调用者能获得锁并进入,其他调用者会等待锁的释放
        await this.ctx.runInLock(orderid,async ()=>{
            await doSomething()
        })
    }
}

Questions & Suggestions

Please open an issue here.

License

MIT

Keywords

egg

FAQs

Package last updated on 13 Oct 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts