@@ -23,6 +23,7 @@ type ConstructorProps = {
23
23
export class RedisCache {
24
24
private readonly client : ReturnType < typeof createClient > ;
25
25
private readonly ttl : number ;
26
+ private readonly keyPrefix = process . env . BUILD_ID ;
26
27
27
28
constructor ( { ttl } : ConstructorProps ) {
28
29
const options = clientOptions [ process . env . ENV ] ;
@@ -64,21 +65,27 @@ export class RedisCache {
64
65
}
65
66
66
67
public async get ( key : string ) : Promise < CacheHandlerValue | null > {
67
- const data = await this . client . get ( key ) ;
68
+ const fullKey = this . getFullKey ( key ) ;
69
+
70
+ const data = await this . client . get ( this . getFullKey ( fullKey ) ) ;
68
71
69
72
if ( ! data ) {
70
- console . log ( `Not found in redis: ${ key } ` ) ;
73
+ console . log ( `Not found in redis: ${ fullKey } ` ) ;
71
74
return null ;
72
75
}
73
76
74
- console . log ( `Found in redis: ${ key } ` ) ;
77
+ console . log ( `Found in redis: ${ fullKey } ` ) ;
75
78
76
79
return JSON . parse ( data ) as CacheHandlerValue ;
77
80
}
78
81
79
82
public async set ( key : string , data : CacheHandlerValue ) {
80
- return this . client . set ( key , JSON . stringify ( data ) , {
83
+ return this . client . set ( this . getFullKey ( key ) , JSON . stringify ( data ) , {
81
84
EX : this . ttl ,
82
85
} ) ;
83
86
}
87
+
88
+ private getFullKey ( key : string ) {
89
+ return `${ this . keyPrefix } _${ key } ` ;
90
+ }
84
91
}
0 commit comments