From 36397bb77dac6895886ea1bd647796d59fda19e8 Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Fri, 28 Apr 2023 20:23:39 +0100 Subject: [PATCH] enabling cluster support for ratelimit cache --- packages/server/src/api/routes/public/index.ts | 8 ++++++-- packages/server/src/environment.ts | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/server/src/api/routes/public/index.ts b/packages/server/src/api/routes/public/index.ts index e2bce1e730..5f93732a06 100644 --- a/packages/server/src/api/routes/public/index.ts +++ b/packages/server/src/api/routes/public/index.ts @@ -42,8 +42,12 @@ if (!env.isTest()) { host: REDIS_OPTS.host, port: REDIS_OPTS.port, }, - password: REDIS_OPTS.opts.password, - database: 1, + password: REDIS_OPTS.opts.password || REDIS_OPTS.opts.redisOptions.password, + } + + if (!env.REDIS_CLUSTERED) { + // Can't set direct redis db in clustered env + options.database = 1 } } rateLimitStore = new Stores.Redis(options) diff --git a/packages/server/src/environment.ts b/packages/server/src/environment.ts index 058e8bdff8..48eb78c41d 100644 --- a/packages/server/src/environment.ts +++ b/packages/server/src/environment.ts @@ -47,6 +47,7 @@ const environment = { MINIO_SECRET_KEY: process.env.MINIO_SECRET_KEY, REDIS_URL: process.env.REDIS_URL, REDIS_PASSWORD: process.env.REDIS_PASSWORD, + REDIS_CLUSTERED: process.env.REDIS_CLUSTERED, HTTP_MIGRATIONS: process.env.HTTP_MIGRATIONS, API_REQ_LIMIT_PER_SEC: process.env.API_REQ_LIMIT_PER_SEC, GOOGLE_CLIENT_ID: process.env.GOOGLE_CLIENT_ID,