加入,退出房间移除房间列表缓存

This commit is contained in:
tianfeng 2025-09-15 18:22:14 +08:00
parent 77cd983ad0
commit 27ac3039b6
2 changed files with 21 additions and 0 deletions

View File

@ -1,11 +1,13 @@
package com.red.circle.live.app.command.user;
import com.red.circle.common.business.dto.cmd.app.AppRoomIdCmd;
import com.red.circle.component.redis.service.RedisService;
import com.red.circle.live.domain.gateway.LiveMicrophoneGateway;
import com.red.circle.live.domain.live.LiveMicrophone;
import com.red.circle.live.domain.live.LiveMusicStatus;
import com.red.circle.live.infra.database.cache.service.LiveMicCacheService;
import com.red.circle.live.infra.database.cache.service.LiveMusicHeartbeatService;
import com.red.circle.other.inner.endpoint.user.region.UserRegionClient;
import com.red.circle.tool.core.collection.CollectionUtils;
import java.util.List;
import java.util.Objects;
@ -24,6 +26,8 @@ public class LiveQuitRoomExe {
private final LiveMicCacheService liveMicCacheService;
private final LiveMicrophoneGateway liveMicrophoneGateway;
private final LiveMusicHeartbeatService liveMusicHeartbeatService;
private final UserRegionClient userRegionClient;
private final RedisService redisService;
public void execute(AppRoomIdCmd cmd) {
// 移除在线用户
@ -50,6 +54,16 @@ public class LiveQuitRoomExe {
&& Objects.equals(musicStatus.getUserId(), cmd.requiredReqUserId())) {
liveMusicHeartbeatService.removeMickUser(cmd.getRoomId());
}
try {
//清空房间列表缓存
String region = userRegionClient.getRegionCode(cmd.requiredReqUserId()).getBody();
String key = cmd.requireReqSysOrigin() + region;
redisService.delete("USER:REGION_ROOM:" + key);
} catch (Exception e) {
// ignore
}
}
}

View File

@ -19,6 +19,7 @@ import com.red.circle.other.app.dto.cmd.room.RoomEntryCmd;
import com.red.circle.other.domain.gateway.user.UserProfileGateway;
import com.red.circle.other.domain.gateway.user.ability.UserRegionGateway;
import com.red.circle.other.infra.database.cache.service.other.RoomManagerCacheService;
import com.red.circle.other.infra.database.cache.service.user.RegionRoomCacheService;
import com.red.circle.other.infra.database.cache.service.user.UserAgoraTokenCacheService;
import com.red.circle.other.infra.database.mongo.entity.live.RoomProfile;
import com.red.circle.other.infra.database.mongo.entity.live.RoomProfileManager;
@ -81,6 +82,7 @@ public class RoomEnterCmdExe {
private final TrtcClient trtcClient;
private final UserAgoraTokenCacheService userAgoraTokenCacheService;
private final TaskMqMessage taskMqMessage;
private final RegionRoomCacheService regionRoomCacheService;
public EntryRoomResponseCO execute(RoomEntryCmd cmd) {
//checkEntryUserId(cmd);
@ -124,6 +126,11 @@ public class RoomEnterCmdExe {
log.error("进房间添加足迹异常:{}", e.getMessage());
}
//清空房间列表缓存
String region = userRegionGateway.getRegionCode(cmd.requiredReqUserId());
String key = cmd.requireReqSysOrigin() + region;
regionRoomCacheService.remove(key);
return new EntryRoomResponseCO()
.setRoomProfile(
new EntryRoomProfileCO()