Skip to content

Commit 73c706e

Browse files
committed
fix: init data 형식 수정
1 parent 299da5e commit 73c706e

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

backend/chatServer/src/room/room.repository.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,24 @@ export class RoomRepository {
3939

4040
private async lindex<T>(key: string, index: number){
4141
const result = await this.redisClient.lindex(key, index);
42-
if(result) return JSON.parse(result) as T;
43-
return undefined;
42+
if(!result) return undefined;
43+
44+
const l = typeof result === 'string' ? result : JSON.parse(result);
45+
return l as T;
4446
}
4547

4648
private async lrange<T>(key: string, start: number, end: number){
4749
const result = await this.redisClient.lrange(key, start, end);
48-
return result as T;
50+
if(!result) return undefined;
51+
const arrayT = result.map((r) => typeof r === 'string' ? r : JSON.parse(r));
52+
return arrayT as T;
4953
}
5054

5155
private async getData<T>(key: string) {
5256
const result = await this.redisClient.get(key);
53-
if(result) return typeof result === 'string' ? result as T : JSON.parse(result) as T;
54-
return undefined;
57+
if(!result) return undefined;
58+
const data = result === 'string' ? result : JSON.parse(result);
59+
return data as T;
5560
}
5661

5762
async isRoomExisted(roomId: string) {

0 commit comments

Comments
 (0)