@zhike/zhike-resource-lock
v1.1.1
Published
lock resource util
Downloads
1
Keywords
Readme
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