炼器堂,练兵场,事件开启,redlock注释

This commit is contained in:
mamengke01
2021-02-24 15:13:46 +08:00
parent dd995e67eb
commit 0e933d1ec4
14 changed files with 157 additions and 85 deletions

View File

@@ -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){