egg-redlock-9

    1.0.2 • Public • Published

    egg-redlock-9

    node version NPM version npm download

    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.js
    exports.redlock9 = {
      enable: true,
      package: 'egg-redlock-9',
    };
    // {app_root}/config/config.default.js
    exports.redis = {
      /* your redis configuration */
    }
    exports.redlock9 = {
      clients: [ 'redis1', 'redis2', 'redis3' ],
      logger: app => e => app.info(e.message), // logger when lock failed, can be false
      options: {
        driftFactor: 0.01, // time in ms
        retryCount: 5,
        retryDelay: 200, // time in ms
        retryJitter: 50, // time in ms
    };
    // {app_root}/app/****.js
    await app.redlock9.run(resouce, ttl, async (lock) => { /* do something */ }); // run in lock
    const success = await app.redlock9.once(resouce, async (lock)=>{ /* do something */ }, wait, duration) // 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

    License

    MIT
    This README was translate by google

    Install

    npm i egg-redlock-9

    DownloadsWeekly Downloads

    23

    Version

    1.0.2

    License

    MIT

    Unpacked Size

    9 kB

    Total Files

    7

    Last publish

    Collaborators

    • avatar