炼器堂,练兵场,事件开启,redlock注释
This commit is contained in:
@@ -9,18 +9,23 @@ interface UserCache {
|
||||
var userCacheMap = new Map<string, UserCache>();
|
||||
|
||||
export function init() {
|
||||
scheduleJob("0/5 * * * * *", clearDirtyData, {name:'clearDirtyData'});
|
||||
scheduleJob("0/5 * * * * *", clearDirtyData, {name:'clearDirtyData'});//每个5秒钟,释放redis锁
|
||||
}
|
||||
|
||||
/**
|
||||
* 释放锁
|
||||
*/
|
||||
export function clearDirtyData() {
|
||||
userCacheMap.forEach(function(userCache, key) {
|
||||
if(nowSeconds() > userCache.time + 10){
|
||||
console.log('show lock =' + JSON.stringify(userCache.lock));
|
||||
userCacheMap.delete(key);
|
||||
releaseLock(key);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据key解锁
|
||||
* @param lockKey
|
||||
*/
|
||||
export function releaseLock(lockKey: string) {
|
||||
var userCache = userCacheMap.get(lockKey);
|
||||
if (!!userCache && userCache.lock){
|
||||
|
||||
Reference in New Issue
Block a user