File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -10,17 +10,18 @@ export default async function createRedisStorage(redisEndpoint: string) {
1010 const redis = require ( 'redis' ) ;
1111
1212 const client = redis . createClient ( { url : redisEndpoint } ) ;
13- await client . connect ( ) ;
1413
1514 // source https://axios-cache-interceptor.js.org/guide/storages#node-redis-storage
1615 return buildStorage ( {
1716 async find ( key ) {
17+ if ( ! client . isReady ) await client . connect ( ) ;
1818 const result = await client . get ( `${ KEY_PREFIX } ${ key } ` ) ;
1919 return result ? ( JSON . parse ( result ) as StorageValue ) : undefined ;
2020 } ,
2121
2222 // eslint-disable-next-line complexity
2323 async set ( key , value , req ) {
24+ if ( ! client . isReady ) await client . connect ( ) ;
2425 await client . set ( `${ KEY_PREFIX } ${ key } ` , JSON . stringify ( value ) , {
2526 PXAT :
2627 // We don't want to keep indefinitely values in the storage if
@@ -39,6 +40,7 @@ export default async function createRedisStorage(redisEndpoint: string) {
3940 } ,
4041
4142 async remove ( key ) {
43+ if ( ! client . isReady ) await client . connect ( ) ;
4244 await client . del ( `${ KEY_PREFIX } ${ key } ` ) ;
4345 } ,
4446 } ) ;
You can’t perform that action at this time.
0 commit comments