fix:bug修改

This commit is contained in:
dzc committed 2026-07-30 20:20:55 +08:00
1 parent f2e2469b61
commit 00a0ab327c
8 files changed
+65 -2

No files matched your search

@@ -74,6 +74,11 @@ public class IMChannelHandler extends SimpleChannelInboundHandler<IMSendInfo> {
RedisMQTemplate redisTemplate = SpringContextHolder.getBean(RedisMQTemplate.class);
String key = String.join(":", IMRedisKey.IM_USER_SERVER_ID, userId.toString(), terminal.toString());
redisTemplate.delete(key);
try {
redisTemplate.opsForHash().put(IMRedisKey.IM_USER_LAST_ACTIVE, userId.toString(), System.currentTimeMillis());
} catch (Exception e) {
log.warn("记录用户最后活跃时间失败,userId:{}", userId, e);
}
log.info("断开连接,userId:{},终端类型:{},{}", userId, terminal, ctx.channel().id().asLongText());
}
}
@@ -96,4 +101,4 @@ public class IMChannelHandler extends SimpleChannelInboundHandler<IMSendInfo> {
}
}
}
}
@@ -42,6 +42,11 @@ public class HeartbeatProcessor extends AbstractMessageProcessor<IMHeartbeatInfo
Integer terminal = ctx.channel().attr(terminalAttr).get();
String key = String.join(":", IMRedisKey.IM_USER_SERVER_ID, userId.toString(), terminal.toString());
redisMQTemplate.expire(key, IMConstant.ONLINE_TIMEOUT_SECOND, TimeUnit.SECONDS);
try {
redisMQTemplate.opsForHash().put(IMRedisKey.IM_USER_LAST_ACTIVE, userId.toString(), System.currentTimeMillis());
} catch (Exception e) {
log.warn("记录用户最后活跃时间失败,userId:{}", userId, e);
}
}
AttributeKey<Long> userIdAttr = AttributeKey.valueOf(ChannelAttrKey.USER_ID);
Long userId = ctx.channel().attr(userIdAttr).get();
@@ -68,6 +68,11 @@ public class LoginProcessor extends AbstractMessageProcessor<IMLoginInfo> {
// 在redis上记录每个user的channelId,15秒没有心跳,则自动过期
String key = String.join(":", IMRedisKey.IM_USER_SERVER_ID, userId.toString(), terminal.toString());
redisMQTemplate.opsForValue().set(key, IMServerGroup.serverId, IMConstant.ONLINE_TIMEOUT_SECOND, TimeUnit.SECONDS);
try {
redisMQTemplate.opsForHash().put(IMRedisKey.IM_USER_LAST_ACTIVE, userId.toString(), System.currentTimeMillis());
} catch (Exception e) {
log.warn("记录用户最后活跃时间失败,userId:{}", userId, e);
}
// 响应ws
IMSendInfo<Object> sendInfo = new IMSendInfo<>();
sendInfo.setCmd(IMCmdType.LOGIN.code());