From 241ea559caaab901d5b3c732e9dd62f2527625fe Mon Sep 17 00:00:00 2001 From: dtfiedler Date: Wed, 25 Sep 2024 13:30:12 -0600 Subject: [PATCH] fix(redis): allow tls config to be used for redis --- src/config.ts | 3 +++ src/init/header-stores.ts | 1 + src/init/resolvers.ts | 3 +++ src/store/redis-kv-store.ts | 3 +++ src/system.ts | 1 + 5 files changed, 11 insertions(+) diff --git a/src/config.ts b/src/config.ts index 5cfef95c..10be111b 100644 --- a/src/config.ts +++ b/src/config.ts @@ -209,6 +209,9 @@ export const REDIS_CACHE_URL = env.varOrDefault( 'redis://localhost:6379', ); +export const REDIS_USE_TLS = + env.varOrDefault('REDIS_USE_TLS', 'false') === 'true'; + // Default Redis TTL export const REDIS_CACHE_TTL_SECONDS = +env.varOrDefault( 'REDIS_CACHE_TTL_SECONDS', diff --git a/src/init/header-stores.ts b/src/init/header-stores.ts index 71b82d69..6cbfcedb 100644 --- a/src/init/header-stores.ts +++ b/src/init/header-stores.ts @@ -50,6 +50,7 @@ const createKvBufferStore = ({ return new RedisKvStore({ redisUrl: config.REDIS_CACHE_URL, ttlSeconds: redisTtlSeconds, + useTls: config.REDIS_USE_TLS, log, }); } diff --git a/src/init/resolvers.ts b/src/init/resolvers.ts index 9b85d9dc..778a5181 100644 --- a/src/init/resolvers.ts +++ b/src/init/resolvers.ts @@ -36,12 +36,14 @@ export const createArNSKvStore = ({ log, type, redisUrl, + useTls, ttlSeconds, maxKeys, }: { type: 'redis' | 'node' | string; log: Logger; redisUrl: string; + useTls: boolean; ttlSeconds: number; maxKeys: number; }): KVBufferStore => { @@ -56,6 +58,7 @@ export const createArNSKvStore = ({ log, redisUrl, ttlSeconds, + useTls, }); } return new NodeKvStore({ ttlSeconds, maxKeys }); diff --git a/src/store/redis-kv-store.ts b/src/store/redis-kv-store.ts index 714bfd0d..9b48c07c 100644 --- a/src/store/redis-kv-store.ts +++ b/src/store/redis-kv-store.ts @@ -28,16 +28,19 @@ export class RedisKvStore implements KVBufferStore { constructor({ log, redisUrl, + useTls, ttlSeconds, }: { log: winston.Logger; redisUrl: string; + useTls: boolean; ttlSeconds: number; }) { this.log = log.child({ class: this.constructor.name }); this.ttlSeconds = ttlSeconds; this.client = createClient({ url: redisUrl, + ...(useTls ? { tls: {} } : {}), // use base tls options if useTls is true }); this.client.on('error', (error: any) => { this.log.error(`Redis error`, { diff --git a/src/system.ts b/src/system.ts index 6ca047e7..b06db503 100644 --- a/src/system.ts +++ b/src/system.ts @@ -558,6 +558,7 @@ export const arnsResolverCache = new KvArnsStore({ redisUrl: config.REDIS_CACHE_URL, ttlSeconds: config.ARNS_CACHE_TTL_SECONDS, maxKeys: config.ARNS_CACHE_MAX_KEYS, + useTls: config.REDIS_USE_TLS, }), });