im问题修复-获取不到用户

This commit is contained in:
liyj 2025-11-18 14:55:10 +08:00
parent 1754272f7f
commit e97416feeb
2 changed files with 6 additions and 4 deletions

View File

@ -146,11 +146,12 @@ public class DistributedSessionService {
*/
public List<Integer> getOnlineUserIds() {
// 方法1: 通过服务器用户集合获取推荐
String serverUsersKey = SERVER_USERS_KEY + new RabbitMQManager().getServerId();
String serverUsersKey = SERVER_USERS_KEY + getServerId();
Set<Object> userIds = redisTemplate.opsForSet().members(serverUsersKey);
if (userIds != null && !userIds.isEmpty()) {
return userIds.stream()
List<Integer> userIdList = new ArrayList<>(userIds.size());
userIdList= userIds.stream()
.map(userIdStr -> {
try {
return Integer.parseInt(userIdStr.toString());
@ -160,6 +161,7 @@ public class DistributedSessionService {
})
.filter(Objects::nonNull)
.collect(Collectors.toList());
return userIdList;
}
return new ArrayList<>();

View File

@ -68,7 +68,7 @@ public class MallsuiteImSocketHandler implements WebSocketHandler {
distributedSessionService.registerUserSession(loginUserId, sessionId, attributes);
// 处理离线消息等原有逻辑...
this.updateOnlineStatus();
// this.updateOnlineStatus();
}
@ -214,7 +214,7 @@ public class MallsuiteImSocketHandler implements WebSocketHandler {
distributedSessionService.removeUserFromGroup(groupId, sessionId);
}
this.updateOnlineStatus();
// this.updateOnlineStatus();
}
@Override