@zhike/zhike-resource-lock

1.1.1 • Public • Published

ATTENTION

这个包处于无人维护状态,没有代码地址,不建议使用. 我是为了修bug迫于无奈,从npm里捞回代码简单改了推了一个新包,有问题不要找我.

RESOURCE LOCK

description

concurrence lock

simple demo

'use strict';

let co = require('co');
let LockUtil = require('./index');

co(function*() {
  let lockUtil = new LockUtil({host: '127.0.0.1', port: 6379}, {
    prefix: 'GREAT-LICHAO',
    frozenTime: 10//auto release lock 5 second
  });
  let ans = yield lockUtil.lock('aaa');
  console.log('get lock success return', ans);

  ans = yield lockUtil.lock('aaa');
  console.log('get lock fail for resource is locked', ans);

  yield lockUtil.unlock('aaa');
  console.log('release lock success return');

  ans = yield lockUtil.lock('aaa');
  console.log('get lock success again return', ans);

  console.log('"lock:GREAT-LICHAO:aaa" will delete after 10 second')

}).then(() => console.log('success'), err => console.log(err.stack));

API

  • Constructor

    • cache required redis的配置或者redis实例
    • opt
      • prefix 前缀
      • frozenTime 自动释放时间
  • lock

    • resourceName 资源名称
  • unlock

    • resourceName 资源名称

Run Tests

npm test

Readme

Keywords

Package Sidebar

Install

npm i @zhike/zhike-resource-lock

Weekly Downloads

1

Version

1.1.1

License

ISC

Unpacked Size

3.94 kB

Total Files

5

Last publish

Collaborators

  • misakisaysyes
  • smartfe
  • jayi
  • zhiker
  • maintao
  • renxing
  • shenggao