From 5f81ba11898461d042eb728727ca667e48334676 Mon Sep 17 00:00:00 2001 From: ciniao <4041990@qq.com> Date: Tue, 26 Dec 2023 14:03:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=BF=E6=8D=A2tanxian=E7=9A=84redis?= =?UTF-8?q?=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/public/gud.ts | 14 ++------------ src/public/tanxian.ts | 15 ++++++++------- 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/src/public/gud.ts b/src/public/gud.ts index 7ff21d5..f861e1f 100644 --- a/src/public/gud.ts +++ b/src/public/gud.ts @@ -19,18 +19,8 @@ export async function clearGud(uid) { G.ioredis.del(`gudVersion:${uid}_ver`); } - if (await G.redis.type('tanxian', uid)) { - console.log('清空tanxian Redis', uid); - // G.redis.del("tanxian", uid); - G.redis.set('tanxian', uid, {}) - } - try { - // console.log('清空friend:list Redis', uid); - // G.redis.hDel("friend:list", uid); - // G.redis.hSet('friend:list', uid, {}) - } catch (e) { - - } + //清空探险缓存 + G.ioredis.del(`tanxian:${uid}`); }; /** diff --git a/src/public/tanxian.ts b/src/public/tanxian.ts index 00c91b8..3605819 100644 --- a/src/public/tanxian.ts +++ b/src/public/tanxian.ts @@ -9,21 +9,22 @@ export class TanXianFun { static async changeData(call: ApiCall, change: dataChange) { G.mongodb.collection('tanxian').updateOne({ uid: call.uid }, { $set: { ...change } }); - - for (let k in change) { - G.redis.set('tanxian', call.uid, k as any, change[k]); - } + let data = await this.getData(call); + Object.assign(data, change); + G.ioredis.set(`tanxian:${call.uid}`, JSON.stringify(data)); } /**获取探险数据 */ static async getData(call: ApiCall, cache = true) { - if (cache && await G.redis.type('tanxian', call.uid) != null) return await G.redis.get('tanxian', call.uid); + if(cache){ + let data = await G.ioredis.get(`tanxian:${call.uid}`); + if (data) return JSON.parse(data); + } let { _id, uid, ...data } = await G.mongodb.collection('tanxian').findOne({ uid: call.uid }); if (!data.eventTime) { data.eventTime = G.time; G.mongodb.collection('tanxian').updateOne({ uid: call.uid }, { $set: { eventTime: G.time } }); } - - await G.redis.set('tanxian', call.uid, data); + await G.ioredis.set(`tanxian:${call.uid}`, JSON.stringify(data)); return data; } /**获取快速探险次数 */