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 {
39
39
40
40
private async lindex < T > ( key : string , index : number ) {
41
41
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 ;
44
46
}
45
47
46
48
private async lrange < T > ( key : string , start : number , end : number ) {
47
49
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 ;
49
53
}
50
54
51
55
private async getData < T > ( key : string ) {
52
56
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 ;
55
60
}
56
61
57
62
async isRoomExisted ( roomId : string ) {
You can’t perform that action at this time.
0 commit comments