登录:登录时候的redis改为原子性

This commit is contained in:
luying
2022-06-13 19:29:58 +08:00
parent f4bfc40cfa
commit d926de282b
2 changed files with 6 additions and 1 deletions
+5 -1
View File
@@ -311,6 +311,7 @@ export async function clearChannelServers() {
* @param sid connector服的那个sid * @param sid connector服的那个sid
*/ */
export async function roleLogin(roleId: string, userCode: string, sid: string, pkgName: string, createTime: number, serverId: number) { export async function roleLogin(roleId: string, userCode: string, sid: string, pkgName: string, createTime: number, serverId: number) {
await redisClient().hincrbyAsync(REDIS_KEY.ONLINE_CNT, roleId, 1);
return await redisClient().hsetAsync(REDIS_KEY.ONLINE_USERS, roleId, `${userCode}|${sid}|${pkgName}|${createTime}|${serverId}`); return await redisClient().hsetAsync(REDIS_KEY.ONLINE_USERS, roleId, `${userCode}|${sid}|${pkgName}|${createTime}|${serverId}`);
} }
@@ -320,7 +321,10 @@ export async function roleLogin(roleId: string, userCode: string, sid: string, p
*/ */
export async function roleLeave(roleId: string) { export async function roleLeave(roleId: string) {
let role = await getRoleOnlineInfo(roleId); let role = await getRoleOnlineInfo(roleId);
await redisClient().hdelAsync(REDIS_KEY.ONLINE_USERS, roleId); let count = await redisClient().hincrbyAsync(REDIS_KEY.ONLINE_CNT, roleId, -1);
if(count <= 0) {
await redisClient().hdelAsync(REDIS_KEY.ONLINE_USERS, roleId);
}
return role; return role;
} }
+1
View File
@@ -213,6 +213,7 @@ export enum REDIS_KEY {
SERVER_OPEN_TIME = 'serverOpenTime', // 服务器开服时间 SERVER_OPEN_TIME = 'serverOpenTime', // 服务器开服时间
ONLINE_USERS ='onlineUsers', // 在线用户情况 ONLINE_USERS ='onlineUsers', // 在线用户情况
ONLINE_TIME ='onlineTime', // 玩家在线时间 ONLINE_TIME ='onlineTime', // 玩家在线时间
ONLINE_CNT ='onlineCnt', // 在线次数
CHANNEL_SERVERS ='chat:channelServers', // 渠道对应的 chat 服务器 Id, CHANNEL_SERVERS ='chat:channelServers', // 渠道对应的 chat 服务器 Id,
USER_GATE_ACTIVITY ='usrGateAct', // 蛮夷入侵玩家排行 USER_GATE_ACTIVITY ='usrGateAct', // 蛮夷入侵玩家排行
GATE_ACTIVITY ='gateAct', // 蛮夷入侵军团排行 GATE_ACTIVITY ='gateAct', // 蛮夷入侵军团排行