egg-redlock-9
The plugin implements distributed locks by reference to redlock and adds two methods, run and once.
中文说明
Install
$ npm i egg-redlock-9 --save
Dependent plugin
Usage
// config/plugin.jsexportsredlock9 = enable: true package: 'egg-redlock-9';
// {app_root}/config/config.default.jsexportsredis = /* your redis configuration */exportsredlock9 = clients: 'redis1' 'redis2' 'redis3' app // logger when lock failed, can be false options: driftFactor: 001 // time in ms retryCount: 5 retryDelay: 200 // time in ms retryJitter: 50 // time in ms;
// {app_root}/app/****.jsawait appredlock9; // run in lockconst success = await appredlock9 // run only once during the duration //You can also use the api of redlock as app.redlock.unlock(lock)
Api docs for redlock
Configuration
see config/config.default.js for more detail.
Unit tests
Run redis-server in localhost first
npm run test