@@ -82,15 +82,6 @@ export default class RedisSocket extends EventEmitter {
82
82
}
83
83
84
84
#createReconnectStrategy( options ?: RedisSocketOptions ) : ReconnectStrategyFunction {
85
- const defaultStrategy = ( retries : number ) => {
86
- // Generate a random jitter between 0 – 200 ms:
87
- const jitter = Math . floor ( Math . random ( ) * 200 ) ;
88
- // Delay is an exponential back off, (times^2) * 50 ms, with a maximum value of 2000 ms:
89
- const delay = Math . min ( Math . pow ( 2 , retries ) * 50 , 2000 ) ;
90
-
91
- return delay + jitter ;
92
- }
93
-
94
85
const strategy = options ?. reconnectStrategy ;
95
86
if ( strategy === false || typeof strategy === 'number' ) {
96
87
return ( ) => strategy ;
@@ -106,12 +97,12 @@ export default class RedisSocket extends EventEmitter {
106
97
return retryIn ;
107
98
} catch ( err ) {
108
99
this . emit ( 'error' , err ) ;
109
- return defaultStrategy ( retries ) ;
100
+ return this . defaultReconnectStrategy ( retries ) ;
110
101
}
111
102
} ;
112
103
}
113
104
114
- return defaultStrategy ;
105
+ return this . defaultReconnectStrategy ;
115
106
}
116
107
117
108
#createSocketFactory( options ?: RedisSocketOptions ) {
@@ -342,4 +333,13 @@ export default class RedisSocket extends EventEmitter {
342
333
this . #isSocketUnrefed = true ;
343
334
this . #socket?. unref ( ) ;
344
335
}
336
+
337
+ defaultReconnectStrategy ( retries : number ) {
338
+ // Generate a random jitter between 0 – 200 ms:
339
+ const jitter = Math . floor ( Math . random ( ) * 200 ) ;
340
+ // Delay is an exponential back off, (times^2) * 50 ms, with a maximum value of 2000 ms:
341
+ const delay = Math . min ( Math . pow ( 2 , retries ) * 50 , 2000 ) ;
342
+
343
+ return delay + jitter ;
344
+ }
345
345
}
0 commit comments