diff --git a/game-server/app/dao/userDao.js b/game-server/app/dao/userDao.js index 25a1077..366cc26 100644 --- a/game-server/app/dao/userDao.js +++ b/game-server/app/dao/userDao.js @@ -5,6 +5,8 @@ const { query_game, query_guild } = require("../lib/db"); const config = pomelo.app.get("redis"); +const userCacheExpire = 60 * 10; + const client = redis.createClient({ url: `redis://${config.host}:${config.port}/${config.db}`, }); @@ -25,6 +27,7 @@ class UserDao { const userInfo = JSON.parse(cacheResult); userInfo.name = name; await client.hSet(`t_user:${uid}`, "value", JSON.stringify(userInfo)); + await client.expire(`t_user:${uid}`, userCacheExpire); return userInfo; } else { return await this.fetchAndCacheUserInfoFromGameDB(uid); @@ -54,7 +57,8 @@ class UserDao { const r = await query_guild(query_insert, [uid, userInfo.name, ""]); await client.hSet(`t_user:${uid}`, "value", JSON.stringify(userInfo)); - + await client.expire(`t_user:${uid}`, userCacheExpire); + return userInfo; } }