From 16980d119970f717318355cec44ae4538895525e Mon Sep 17 00:00:00 2001 From: Diego Patino Date: Wed, 25 Oct 2023 13:16:34 -0700 Subject: [PATCH 1/2] feat: add TLS support for Redis --- .docker.env | 1 + .example.env | 2 ++ server/env.ts | 1 + server/redis.ts | 3 ++- 4 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.docker.env b/.docker.env index 00c318567..d3dddf92b 100644 --- a/.docker.env +++ b/.docker.env @@ -23,6 +23,7 @@ REDIS_HOST=redis REDIS_PORT=6379 REDIS_PASSWORD= REDIS_DB= +REDIS_SSL=false # Disable registration DISALLOW_REGISTRATION=false diff --git a/.example.env b/.example.env index f739887d0..175e480f9 100644 --- a/.example.env +++ b/.example.env @@ -25,6 +25,8 @@ REDIS_PASSWORD= # Optional: The number for Redis database, between 0 and 15. Defaults to 0. # If you don't know what this is, then you probably don't need to change it. REDIS_DB=0 +# Optional: Add rediss:// to the connection string +REDIS_SSL=false # Disable registration DISALLOW_REGISTRATION=false diff --git a/server/env.ts b/server/env.ts index 075178c01..da4783538 100644 --- a/server/env.ts +++ b/server/env.ts @@ -20,6 +20,7 @@ const env = cleanEnv(process.env, { REDIS_PORT: num({ default: 6379 }), REDIS_PASSWORD: str({ default: "" }), REDIS_DB: num({ default: 0 }), + REDIS_SSL: bool({ default: false }), USER_LIMIT_PER_DAY: num({ default: 50 }), NON_USER_COOLDOWN: num({ default: 10 }), DEFAULT_MAX_STATS_PER_LINK: num({ default: 5000 }), diff --git a/server/redis.ts b/server/redis.ts index 7df6f7cbe..e74c6c892 100644 --- a/server/redis.ts +++ b/server/redis.ts @@ -6,7 +6,8 @@ const client = new Redis({ host: env.REDIS_HOST, port: env.REDIS_PORT, db: env.REDIS_DB, - ...(env.REDIS_PASSWORD && { password: env.REDIS_PASSWORD }) + ...(env.REDIS_PASSWORD && { password: env.REDIS_PASSWORD }), + ...(env.REDIS_SSL && { tls: {} }) }); export default client; From f076a8154ba16d67550b2e5f9763d63330368ab4 Mon Sep 17 00:00:00 2001 From: Diego Patino Date: Thu, 26 Oct 2023 17:54:12 -0700 Subject: [PATCH 2/2] feat: add key prefix for Redis --- .docker.env | 1 + .example.env | 2 ++ server/env.ts | 1 + server/redis.ts | 3 ++- 4 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.docker.env b/.docker.env index d3dddf92b..d46ae7153 100644 --- a/.docker.env +++ b/.docker.env @@ -24,6 +24,7 @@ REDIS_PORT=6379 REDIS_PASSWORD= REDIS_DB= REDIS_SSL=false +REDIS_KEYPREFIX= # Disable registration DISALLOW_REGISTRATION=false diff --git a/.example.env b/.example.env index 175e480f9..7c8bbd578 100644 --- a/.example.env +++ b/.example.env @@ -27,6 +27,8 @@ REDIS_PASSWORD= REDIS_DB=0 # Optional: Add rediss:// to the connection string REDIS_SSL=false +# Optional: Prefix for keys in Redis +REDIS_KEYPREFIX= # Disable registration DISALLOW_REGISTRATION=false diff --git a/server/env.ts b/server/env.ts index da4783538..8d780c6ad 100644 --- a/server/env.ts +++ b/server/env.ts @@ -21,6 +21,7 @@ const env = cleanEnv(process.env, { REDIS_PASSWORD: str({ default: "" }), REDIS_DB: num({ default: 0 }), REDIS_SSL: bool({ default: false }), + REDIS_KEYPREFIX: str({ default: "" }), USER_LIMIT_PER_DAY: num({ default: 50 }), NON_USER_COOLDOWN: num({ default: 10 }), DEFAULT_MAX_STATS_PER_LINK: num({ default: 5000 }), diff --git a/server/redis.ts b/server/redis.ts index e74c6c892..7e2806dca 100644 --- a/server/redis.ts +++ b/server/redis.ts @@ -7,7 +7,8 @@ const client = new Redis({ port: env.REDIS_PORT, db: env.REDIS_DB, ...(env.REDIS_PASSWORD && { password: env.REDIS_PASSWORD }), - ...(env.REDIS_SSL && { tls: {} }) + ...(env.REDIS_SSL && { tls: {} }), + ...(env.REDIS_KEYPREFIX && { keyPrefix: env.REDIS_KEYPREFIX }) }); export default client;