Skip to content

Commit

Permalink
fix(redis): allow tls config to be used for redis
Browse files Browse the repository at this point in the history
  • Loading branch information
dtfiedler committed Sep 25, 2024
1 parent 6242301 commit 11eb323
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ services:
- IO_PROCESS_ID=${IO_PROCESS_ID:-}
- CHAIN_CACHE_TYPE=${CHAIN_CACHE_TYPE:-redis}
- REDIS_CACHE_URL=${REDIS_CACHE_URL:-redis://redis:6379}
- REDIS_USE_TLS=${REDIS_USE_TLS:-false}
- REDIS_CACHE_TTL_SECONDS=${REDIS_CACHE_TTL_SECONDS:-}
- NODE_JS_MAX_OLD_SPACE_SIZE=${NODE_JS_MAX_OLD_SPACE_SIZE:-}
- ENABLE_FS_HEADER_CACHE_CLEANUP=${ENABLE_FS_HEADER_CACHE_CLEANUP:-true}
Expand Down
3 changes: 3 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
1 change: 1 addition & 0 deletions src/init/header-stores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const createKvBufferStore = ({
return new RedisKvStore({
redisUrl: config.REDIS_CACHE_URL,
ttlSeconds: redisTtlSeconds,
useTls: config.REDIS_USE_TLS,
log,
});
}
Expand Down
3 changes: 3 additions & 0 deletions src/init/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand All @@ -56,6 +58,7 @@ export const createArNSKvStore = ({
log,
redisUrl,
ttlSeconds,
useTls,
});
}
return new NodeKvStore({ ttlSeconds, maxKeys });
Expand Down
3 changes: 3 additions & 0 deletions src/store/redis-kv-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`, {
Expand Down
1 change: 1 addition & 0 deletions src/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}),
});

Expand Down

0 comments on commit 11eb323

Please sign in to comment.