登录:登录时候的redis改为原子性
This commit is contained in:
@@ -311,6 +311,7 @@ export async function clearChannelServers() {
|
||||
* @param sid connector服的那个sid
|
||||
*/
|
||||
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}`);
|
||||
}
|
||||
|
||||
@@ -320,7 +321,10 @@ export async function roleLogin(roleId: string, userCode: string, sid: string, p
|
||||
*/
|
||||
export async function roleLeave(roleId: string) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -213,6 +213,7 @@ export enum REDIS_KEY {
|
||||
SERVER_OPEN_TIME = 'serverOpenTime', // 服务器开服时间
|
||||
ONLINE_USERS ='onlineUsers', // 在线用户情况
|
||||
ONLINE_TIME ='onlineTime', // 玩家在线时间
|
||||
ONLINE_CNT ='onlineCnt', // 在线次数
|
||||
CHANNEL_SERVERS ='chat:channelServers', // 渠道对应的 chat 服务器 Id,
|
||||
USER_GATE_ACTIVITY ='usrGateAct', // 蛮夷入侵玩家排行
|
||||
GATE_ACTIVITY ='gateAct', // 蛮夷入侵军团排行
|
||||
|
||||
Reference in New Issue
Block a user