File tree Expand file tree Collapse file tree 1 file changed +10
-5
lines changed
backend/chatServer/src/room Expand file tree Collapse file tree 1 file changed +10
-5
lines changed Original file line number Diff line number Diff 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 ) {
You can’t perform that action at this time.
0 commit comments