From a3178fb2137f3e161d2dab3573677d4949090cdc Mon Sep 17 00:00:00 2001 From: miles Date: Sat, 24 Feb 2024 18:56:12 +0800 Subject: [PATCH] Feature/expose redis database via environment variable (#3036) * Expose Redis database via environment variable * Update changelog --- CHANGELOG.md | 1 + README.md | 1 + apps/api/src/app/app.module.ts | 1 + apps/api/src/app/redis-cache/redis-cache.module.ts | 1 + apps/api/src/services/configuration/configuration.service.ts | 1 + apps/api/src/services/interfaces/environment.interface.ts | 1 + 6 files changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c7dc3807..61cb9fcd5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- Exposed the database index of _Redis_ as an environment variable (`REDIS_DB`) - Upgraded `prisma` from version `5.9.1` to `5.10.2` ## 2.55.0 - 2024-02-22 diff --git a/README.md b/README.md index 0d4bf3cfb..c82ad50c3 100644 --- a/README.md +++ b/README.md @@ -99,6 +99,7 @@ We provide official container images hosted on [Docker Hub](https://hub.docker.c | `POSTGRES_DB` | | The name of the _PostgreSQL_ database | | `POSTGRES_PASSWORD` | | The password of the _PostgreSQL_ database | | `POSTGRES_USER` | | The user of the _PostgreSQL_ database | +| `REDIS_DB` | `0` | The database index of _Redis_ | | `REDIS_HOST` | | The host where _Redis_ is running | | `REDIS_PASSWORD` | | The password of _Redis_ | | `REDIS_PORT` | | The port where _Redis_ is running | diff --git a/apps/api/src/app/app.module.ts b/apps/api/src/app/app.module.ts index 506a76a8a..5f2be5c8e 100644 --- a/apps/api/src/app/app.module.ts +++ b/apps/api/src/app/app.module.ts @@ -53,6 +53,7 @@ import { UserModule } from './user/user.module'; BenchmarkModule, BullModule.forRoot({ redis: { + db: parseInt(process.env.REDIS_DB ?? '0', 10), host: process.env.REDIS_HOST, port: parseInt(process.env.REDIS_PORT ?? '6379', 10), password: process.env.REDIS_PASSWORD diff --git a/apps/api/src/app/redis-cache/redis-cache.module.ts b/apps/api/src/app/redis-cache/redis-cache.module.ts index 8acd644f6..4b4168168 100644 --- a/apps/api/src/app/redis-cache/redis-cache.module.ts +++ b/apps/api/src/app/redis-cache/redis-cache.module.ts @@ -15,6 +15,7 @@ import { RedisCacheService } from './redis-cache.service'; inject: [ConfigurationService], useFactory: async (configurationService: ConfigurationService) => { return { + db: configurationService.get('REDIS_DB'), host: configurationService.get('REDIS_HOST'), max: configurationService.get('MAX_ITEM_IN_CACHE'), password: configurationService.get('REDIS_PASSWORD'), diff --git a/apps/api/src/services/configuration/configuration.service.ts b/apps/api/src/services/configuration/configuration.service.ts index 61a54daa1..eb82be418 100644 --- a/apps/api/src/services/configuration/configuration.service.ts +++ b/apps/api/src/services/configuration/configuration.service.ts @@ -43,6 +43,7 @@ export class ConfigurationService { MAX_ACTIVITIES_TO_IMPORT: num({ default: Number.MAX_SAFE_INTEGER }), MAX_ITEM_IN_CACHE: num({ default: 9999 }), PORT: port({ default: 3333 }), + REDIS_DB: num({ default: 0 }), REDIS_HOST: str({ default: 'localhost' }), REDIS_PASSWORD: str({ default: '' }), REDIS_PORT: port({ default: 6379 }), diff --git a/apps/api/src/services/interfaces/environment.interface.ts b/apps/api/src/services/interfaces/environment.interface.ts index 54abe22be..09d0b0e5d 100644 --- a/apps/api/src/services/interfaces/environment.interface.ts +++ b/apps/api/src/services/interfaces/environment.interface.ts @@ -30,6 +30,7 @@ export interface Environment extends CleanedEnvAccessors { MAX_ACTIVITIES_TO_IMPORT: number; MAX_ITEM_IN_CACHE: number; PORT: number; + REDIS_DB: number; REDIS_HOST: string; REDIS_PASSWORD: string; REDIS_PORT: number;