Skip to content

Commit

Permalink
fix: init data 형식 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
hoeeeeeh committed Dec 2, 2024
1 parent 73c706e commit 905c03a
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions backend/chatServer/src/room/room.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,34 @@ export class RoomRepository {
private async lindex<T>(key: string, index: number){
const result = await this.redisClient.lindex(key, index);
if(!result) return undefined;

const l = typeof result === 'string' ? result : JSON.parse(result);
return l as T;
try {
return JSON.parse(result) as T;
} catch {
return result as T;
}
}

private async lrange<T>(key: string, start: number, end: number){
const result = await this.redisClient.lrange(key, start, end);
if(!result) return undefined;
const arrayT = result.map((r) => typeof r === 'string' ? r : JSON.parse(r));
const arrayT = result.map((r) => {
try {
return JSON.parse(r);
} catch {
return r;
}
});
return arrayT as T;
}

private async getData<T>(key: string) {
const result = await this.redisClient.get(key);
if(!result) return undefined;
const data = result === 'string' ? result : JSON.parse(result);
return data as T;
try {
return JSON.parse(result) as T;
} catch {
return result as T;
}
}

async isRoomExisted(roomId: string) {
Expand Down

0 comments on commit 905c03a

Please sign in to comment.