Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(redis): allow tls config to be used for redis #211

Merged
merged 3 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
7 changes: 6 additions & 1 deletion src/init/header-stores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,16 @@ const createKvBufferStore = ({
pathKey,
type,
log,
redisUrl = config.REDIS_CACHE_URL,
redisTtlSeconds = config.REDIS_CACHE_TTL_SECONDS,
useTls = config.REDIS_USE_TLS,
}: {
pathKey: string;
type: string;
log: winston.Logger;
redisUrl?: string;
redisTtlSeconds?: number;
useTls?: boolean;
}): KVBufferStore => {
log.info(`Using ${type} for KVBufferStore for ${pathKey}`);
switch (type) {
Expand All @@ -48,8 +52,9 @@ const createKvBufferStore = ({
}
case 'redis': {
return new RedisKvStore({
redisUrl: config.REDIS_CACHE_URL,
redisUrl,
ttlSeconds: redisTtlSeconds,
useTls,
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
5 changes: 5 additions & 0 deletions src/store/redis-kv-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,21 @@ 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,
socket: {
tls: useTls,
},
});
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