@@ -42,6 +42,22 @@ enum ADDITIONAL_IDENTIFIER {
42
42
Confirmation = ":confirmation" ,
43
43
}
44
44
45
+ const createRedisClient = ( ) : Redis | null => {
46
+ if ( redisHost || redisUri ) {
47
+ const redisOptions : { password ?: string ; tls ?: { } ; } = { } ;
48
+ if ( redisPassword ) redisOptions . password = redisPassword ;
49
+ if ( redisTls ) redisOptions . tls = { } ;
50
+
51
+ return isSingleRedis
52
+ ? new Redis ( redisUri ?? { host : redisHost , port : redisPort , password : redisPassword } )
53
+ : new Redis . Cluster (
54
+ [ { host : redisHost , port : redisPort } ] ,
55
+ { dnsLookup : ( address , callback ) => callback ( null , address , 4 ) , redisOptions}
56
+ ) ;
57
+ }
58
+ return null ;
59
+ } ;
60
+
45
61
export class AdapterCacheService extends CacheService {
46
62
47
63
constructor ( server : HapiServer ) {
@@ -253,49 +269,16 @@ export class AdapterCacheService extends CacheService {
253
269
throw Boom . notFound ( "Cannot find the given form" ) ;
254
270
}
255
271
256
- private getRedisClient ( ) {
257
- if ( redisHost || redisUri ) {
258
- const redisOptions : {
259
- password ?: string ;
260
- tls ?: { } ;
261
- } = { } ;
262
-
263
- if ( redisPassword ) {
264
- redisOptions . password = redisPassword ;
265
- }
266
-
267
- if ( redisTls ) {
268
- redisOptions . tls = { } ;
269
- }
270
-
271
- const client = isSingleRedis
272
- ? new Redis (
273
- redisUri ?? {
274
- host : redisHost ,
275
- port : redisPort ,
276
- password : redisPassword ,
277
- }
278
- )
279
- : new Redis . Cluster (
280
- [
281
- {
282
- host : redisHost ,
283
- port : redisPort ,
284
- } ,
285
- ] ,
286
- {
287
- dnsLookup : ( address , callback ) => callback ( null , address , 4 ) ,
288
- redisOptions,
289
- }
290
- ) ;
291
- return client ;
292
- } else {
293
- console . log ( {
294
- ...LOGGER_DATA ,
295
- message : `[FORM-CACHE] using memory caching` ,
296
- } )
297
- }
298
- }
272
+ private getRedisClient ( ) : Redis | null {
273
+ const client = createRedisClient ( ) ;
274
+ if ( ! client ) {
275
+ console . log ( {
276
+ ...LOGGER_DATA ,
277
+ message : `[FORM-CACHE] using memory caching` ,
278
+ } ) ;
279
+ }
280
+ return client ;
281
+ }
299
282
}
300
283
301
284
export const catboxProvider = ( ) => {
@@ -305,49 +288,16 @@ export const catboxProvider = () => {
305
288
*/
306
289
const provider = {
307
290
constructor : redisHost || redisUri ? CatboxRedis . Engine : CatboxMemory . Engine ,
308
- options : { } ,
291
+ options : { partition } ,
309
292
} ;
310
293
311
294
if ( redisHost || redisUri ) {
312
- console . log ( "Starting redis session management" )
313
- const redisOptions : {
314
- password ?: string ;
315
- tls ?: { } ;
316
- } = { } ;
317
-
318
- if ( redisPassword ) {
319
- redisOptions . password = redisPassword ;
320
- }
321
-
322
- if ( redisTls ) {
323
- redisOptions . tls = { } ;
324
- }
325
-
326
- const client = isSingleRedis
327
- ? new Redis (
328
- redisUri ?? {
329
- host : redisHost ,
330
- port : redisPort ,
331
- password : redisPassword ,
332
- }
333
- )
334
- : new Redis . Cluster (
335
- [
336
- {
337
- host : redisHost ,
338
- port : redisPort ,
339
- } ,
340
- ] ,
341
- {
342
- dnsLookup : ( address , callback ) => callback ( null , address , 4 ) ,
343
- redisOptions,
344
- }
345
- ) ;
346
- provider . options = { client, partition} ;
347
- console . log ( `Redis Url : ${ redisUri } session management` ) ;
295
+ console . log ( "Starting redis session management" ) ;
296
+ const client = createRedisClient ( ) ;
297
+ provider . options = { client, partition} ;
298
+ console . log ( `Redis Url : ${ redisUri } session management` ) ;
348
299
} else {
349
- console . log ( "Starting in memory session management" )
350
- provider . options = { partition} ;
300
+ console . log ( "Starting in memory session management" ) ;
351
301
}
352
302
353
303
return provider ;
0 commit comments