@@ -28,12 +28,16 @@ abstract class RedisCacheBase implements CacheStore {
2828
2929 async connect ( ) {
3030 if ( this . client ) {
31- await this . client . connect ( ) ;
32- const pong = await this . ping ( ) ;
31+ try {
32+ await this . client . connect ( ) ;
33+ const pong = await this . ping ( ) ;
3334
34- if ( pong === 'PONG' ) {
35- cacheConsole . info ( 'Connected to Redis' ) ;
36- return ;
35+ if ( pong === 'PONG' ) {
36+ cacheConsole . info ( 'Connected to Redis' ) ;
37+ return ;
38+ }
39+ } catch ( error : unknown ) {
40+ cacheConsole . error ( error ) ;
3741 }
3842 }
3943 cacheConsole . warn ( 'No Redis client initialized, skipping' ) ;
@@ -46,14 +50,14 @@ abstract class RedisCacheBase implements CacheStore {
4650 }
4751 }
4852
49- protected getSocketOptions ( url : URL ) {
50- const certFile = url . searchParams . get ( 'cert' ) ;
51- const keyFile = url . searchParams . get ( 'key' ) ;
52- const caFile = url . searchParams . get ( 'certroot' ) ;
53+ protected getSocketOptions ( url ? : URL ) {
54+ const certFile = url ? .searchParams . get ( 'cert' ) ;
55+ const keyFile = url ? .searchParams . get ( 'key' ) ;
56+ const caFile = url ? .searchParams . get ( 'certroot' ) ;
5357
5458 return {
55- rejectUnauthorized : yes ( url . searchParams . get ( 'reject_unauthorized' ) ) ,
56- tls : url . protocol === 'rediss' ,
59+ rejectUnauthorized : yes ( url ? .searchParams . get ( 'reject_unauthorized' ) ) ,
60+ tls : url ? .protocol === 'rediss' ,
5761 cert : certFile ? fs . readFileSync ( certFile ) . toString ( ) : undefined ,
5862 key : keyFile ? fs . readFileSync ( keyFile ) . toString ( ) : undefined ,
5963 ca : caFile ? fs . readFileSync ( caFile ) . toString ( ) : undefined ,
@@ -64,7 +68,11 @@ abstract class RedisCacheBase implements CacheStore {
6468 return false ;
6569 }
6670
67- return Math . min ( retries * 50 , 500 ) ;
71+ if ( retries > 5 ) {
72+ return new Error ( 'Too many retries' ) ;
73+ }
74+
75+ return retries * 500 ;
6876 } ,
6977 } ;
7078 }
@@ -81,11 +89,12 @@ export class RedisCache extends RedisCacheBase {
8189 if ( redisUrl ) {
8290 this . client = createClient ( {
8391 url : conditional ( ! yes ( redisUrl ) && redisUrl ) ,
84- socket : trySafe ( ( ) => this . getSocketOptions ( new URL ( redisUrl ) ) ) ,
92+ socket : this . getSocketOptions ( trySafe ( ( ) => new URL ( redisUrl ) ) ) ,
8593 } ) ;
8694
8795 this . client . on ( 'error' , ( error ) => {
8896 void appInsights . trackException ( error ) ;
97+ cacheConsole . error ( error ) ;
8998 } ) ;
9099 }
91100 }
@@ -127,6 +136,7 @@ export class RedisClusterCache extends RedisCacheBase {
127136
128137 this . client . on ( 'error' , ( error ) => {
129138 void appInsights . trackException ( error ) ;
139+ cacheConsole . error ( error ) ;
130140 } ) ;
131141 }
132142
0 commit comments