egg-locker
v2.0.0
Published
[![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
Downloads
4
Readme
egg-locker
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.