From 4a9f5cb02e73f6abf6aadf8e4a76edbb7e304796 Mon Sep 17 00:00:00 2001 From: chenkai Date: Tue, 26 Dec 2023 13:54:49 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20DldFight=20=E6=8E=A5=E5=8F=A3=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E7=8E=A9=E5=AE=B6=E9=94=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api_s2c/wzry/ApiDldFight.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/api_s2c/wzry/ApiDldFight.ts b/src/api_s2c/wzry/ApiDldFight.ts index 1f1b56e..bb98360 100644 --- a/src/api_s2c/wzry/ApiDldFight.ts +++ b/src/api_s2c/wzry/ApiDldFight.ts @@ -8,8 +8,15 @@ import { PublicShared } from "../../shared/public/public"; import { HongDianChange } from "../hongdian/fun"; const maxScore = 269; // 积分上限 +const lockPrefix = 'lock:DldFight:'; export default async function (call: ApiCall) { + const lockKey = lockPrefix + call.uid; + const gotLock = await G.ioredis.setnx(lockKey, 1); + if (!gotLock) { + return call.errorCode(-101); // -101 并发请求, 告知客户端稍后再试 request_too_fast + } + await G.ioredis.pexpire(lockKey, 500); // 设置 ttl 避免死锁. 策划要求: 500ms let status = await WangZheRongYaofun.getWangZheStatus(); if (status.status != 3) { // 未到大乱斗时间 @@ -75,7 +82,7 @@ export default async function (call: ApiCall) { _mydata.jifen = _myFight.jifen; HongDianChange.sendChangeKey(call.uid, ['wzryhd']); - + await G.ioredis.del(lockKey); call.succ({ mydata: _mydata, result: result,