捐赠:添加锁

This commit is contained in:
luying
2022-05-06 16:51:54 +08:00
parent 58f2c98aec
commit 399057c947
4 changed files with 16 additions and 12 deletions
@@ -61,7 +61,7 @@ export class DonationHandler {
const guildCode: string = session.get('guildCode'); const guildCode: string = session.get('guildCode');
let res: any = await lockData(serverId, DATA_NAME.DONATE, guildCode);// 锁定资金的增加 let res: any = await lockData(serverId, DATA_NAME.DONATE, guildCode);// 锁定资金的增加
try { try {
if (!res) { if (!!res.err) {
return resResult(STATUS.REDLOCK_ERR); return resResult(STATUS.REDLOCK_ERR);
} }
+12 -9
View File
@@ -73,16 +73,19 @@ export async function lockDataWithNoParam(dataName: string) {
return await lock(key); return await lock(key);
} }
function lock(lockKey: string) { async function lock(lockKey: string) {
return _redlockCache.redlock.lock(lockKey, _redlockCache.ttl).then(function(lock) { return new Promise((resolve) => {
setLock(lockKey, lock); _redlockCache.redlock.lock(lockKey, _redlockCache.ttl, function(err, lock) {
return {err: null, releaseCallback: releaseCallback.bind(null, lockKey)}; if(err) {
}).catch(function(err) { return resolve({ err })
console.error(err); }
return { err }; setLock(lockKey, lock);
}); return resolve({err: null, releaseCallback: releaseCallback.bind(null, lockKey)});
});
})
} }
export async function releaseCallback(lockKey: string) {
function releaseCallback(lockKey: string) {
releaseLock(lockKey); releaseLock(lockKey);
} }
+1 -1
View File
@@ -6,7 +6,7 @@ export const STATUS = {
INTERNAL_ERR: { code: 3, simStr: '内部错误' }, INTERNAL_ERR: { code: 3, simStr: '内部错误' },
CONNECTOR_ERR: { code: 4, simStr: '连接服配置错误' }, CONNECTOR_ERR: { code: 4, simStr: '连接服配置错误' },
LOGIN_ERR: { code: 5, simStr: '检测到您的账号异地登录,已被迫下线' }, LOGIN_ERR: { code: 5, simStr: '检测到您的账号异地登录,已被迫下线' },
REDLOCK_ERR: { code: 6, simStr: 'redlock错误' }, REDLOCK_ERR: { code: 6, simStr: '请勿频繁操作' },
SERVER_MAINTENANCE: { code: 7, simStr: '服务器维护中' }, SERVER_MAINTENANCE: { code: 7, simStr: '服务器维护中' },
VERSION_ERR: { code: 8, simStr: '版本号太低,请更新' }, VERSION_ERR: { code: 8, simStr: '版本号太低,请更新' },
BLOCK_WORDS: { code: 9, simStr: '内容有不合法词汇' }, BLOCK_WORDS: { code: 9, simStr: '内容有不合法词汇' },
+2 -1
View File
@@ -13,6 +13,7 @@
{ "id": 4, "desc": "私聊", "route": "chat.chatHandler.sendPrivateMessage", "param": {}, "interval": 1000 }, { "id": 4, "desc": "私聊", "route": "chat.chatHandler.sendPrivateMessage", "param": {}, "interval": 1000 },
{ "id": 5, "desc": "发送弹幕", "route": "battle.barrageHandler.sendBarrage", "param": {}, "interval": 1000 }, { "id": 5, "desc": "发送弹幕", "route": "battle.barrageHandler.sendBarrage", "param": {}, "interval": 1000 },
{ "id": 6, "desc": "获取信息", "route": "connector.entryHandler.getData", "param": {}, "interval": 1000 }, { "id": 6, "desc": "获取信息", "route": "connector.entryHandler.getData", "param": {}, "interval": 1000 },
{ "id": 7, "desc": "刷新信息", "route": "connector.entryHandler.refresh", "param": {}, "interval": 1000 } { "id": 7, "desc": "刷新信息", "route": "connector.entryHandler.refresh", "param": {}, "interval": 1000 },
{ "id": 8, "desc": "捐赠", "route": "guild.donateHandler.donate", "param": {}, "interval": 200 }
] ]
} }