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

feat: add TLS support for Redis #718

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions .docker.env
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ REDIS_HOST=redis
REDIS_PORT=6379
REDIS_PASSWORD=
REDIS_DB=
REDIS_SSL=false
REDIS_KEYPREFIX=

# Disable registration
DISALLOW_REGISTRATION=false
Expand Down
4 changes: 4 additions & 0 deletions .example.env
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ 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
# Optional: Prefix for keys in Redis
REDIS_KEYPREFIX=

# Disable registration
DISALLOW_REGISTRATION=false
Expand Down
2 changes: 2 additions & 0 deletions server/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const env = cleanEnv(process.env, {
REDIS_PORT: num({ default: 6379 }),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If TLS is enabled, should we change the default port to 6380 if there isn't one set explicitly?
Like:
TLS disabled => REDIS_PORT=env.REDIS_PORT or 6379
TLS enabled => REDIS_PORT=env.REDIS_PORT or 6380

REDIS_PASSWORD: str({ default: "" }),
REDIS_DB: num({ default: 0 }),
REDIS_SSL: bool({ default: false }),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why use a "deprecated" term like SSL instead of TLS directly?
PS: Some projects use REDIS_PROTOCOL (here you are proposing REDIS_SSL) as a flag with 2 options: (redis, rediss) as in (redis://:<password>@<host>:<port>/<db>, rediss://:<password>@<host>:<port>/<db>).

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 }),
Expand Down
4 changes: 3 additions & 1 deletion server/redis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ 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: {} }),
...(env.REDIS_KEYPREFIX && { keyPrefix: env.REDIS_KEYPREFIX })
});

export default client;
Expand Down