gemercheung 2 anni fa
parent
commit
543e4ee0c8
3 ha cambiato i file con 17 aggiunte e 2 eliminazioni
  1. 1 1
      src/common/envs/production.env
  2. 1 0
      src/room/config.d.ts
  3. 15 1
      src/room/users/users.service.ts

+ 1 - 1
src/common/envs/production.env

@@ -5,7 +5,7 @@ SOCKET_PATH="/ws-sync"
 SOCKET_USE_MSPACK=1
 REDIS_HOST=127.0.0.1
 REDIS_PORT=6379
-REDIS_PASSWORD=JK20220120JIK
+REDIS_PASSWORD=redis9394
 REDIS_DB=8
 REDIS_ADAPTER_DB=8
 REDIS_PREFIX=chat

+ 1 - 0
src/room/config.d.ts

@@ -1,6 +1,7 @@
 interface RoomConfigType {
   limit?: IntRange<5, 51>;
   masterId?: string;
+  ttl?: number;
 }
 
 type Enumerate<

+ 15 - 1
src/room/users/users.service.ts

@@ -10,7 +10,7 @@ export class UsersService {
     @InjectRedis() private readonly redis: Redis,
     @Inject(forwardRef(() => RoomService))
     private roomService: RoomService,
-  ) {}
+  ) { }
 
   async isUserInRooms(RoomId: string, UserId: string): Promise<boolean> {
     const res = await this.redis.hexists(
@@ -119,6 +119,20 @@ export class UsersService {
       `'room setting: ${RoomId},isExist:${isExist} `,
       'room-config',
     );
+    // 存在正常房间ttl存活时间
+    if (RoomConfig?.ttl) {
+      this.roomService.logger.log(
+        `'正常设置房间-ttl: ${RoomConfig.ttl}`,
+        'room-ttl',
+      );
+      await this.redis.set(
+        `kankan:socket:tempRoom:${RoomId}`,
+        '',
+        'EX',
+        RoomConfig.ttl,
+      );
+    }
+
     if (isExist) {
       const config = JSON.parse(isExist);
       const obj = Object.assign({}, config, RoomConfig);