diff --git a/apps/api/config.ts b/apps/api/config.ts index 31c1712..44dae16 100644 --- a/apps/api/config.ts +++ b/apps/api/config.ts @@ -24,7 +24,9 @@ export const config = () => ({ }, }, redis: { - url: process.env.REDIS_URL || '127.0.0.1', + host: process.env.REDIS_HOST || '127.0.0.1', + port: parseInt(process.env.REDIS_PORT || '6379'), + password: process.env.REDIS_PASSWORD, }, }, }) diff --git a/apps/api/src/main.ts b/apps/api/src/main.ts index 547ce0a..e31686e 100644 --- a/apps/api/src/main.ts +++ b/apps/api/src/main.ts @@ -86,8 +86,9 @@ async function bootstrap() { const pubSubApp = await NestFactory.createMicroservice(PubSubListenerModule.forRoot(config), { transport: Transport.REDIS, options: { - host: appConfigService.redisUrl, - port: 6379, + host: appConfigService.redisHost, + port: appConfigService.redisPort, + password: appConfigService.redisPassword || undefined, retryAttempts: 100, retryDelay: 1000, retryStrategy: () => 1000, diff --git a/apps/cache-warmer/config.ts b/apps/cache-warmer/config.ts index bdd5b4c..93b1012 100644 --- a/apps/cache-warmer/config.ts +++ b/apps/cache-warmer/config.ts @@ -18,7 +18,9 @@ export const config = () => ({ }, services: { redis: { - url: process.env.REDIS_URL || '127.0.0.1', + host: process.env.REDIS_HOST || '127.0.0.1', + port: parseInt(process.env.REDIS_PORT || '6379'), + password: process.env.REDIS_PASSWORD, }, }, }) diff --git a/apps/cache-warmer/src/main.ts b/apps/cache-warmer/src/main.ts index 7073f67..b0a1762 100644 --- a/apps/cache-warmer/src/main.ts +++ b/apps/cache-warmer/src/main.ts @@ -20,8 +20,9 @@ async function bootstrap() { const pubSubApp = await NestFactory.createMicroservice(PubSubListenerModule.forRoot(config), { transport: Transport.REDIS, options: { - host: appConfigService.redisUrl, - port: 6379, + host: appConfigService.redisHost, + port: appConfigService.redisPort, + password: appConfigService.redisPassword || undefined, retryAttempts: 100, retryDelay: 1000, retryStrategy: () => 1000, diff --git a/apps/queue-worker/config.ts b/apps/queue-worker/config.ts index 821cba4..9c69317 100644 --- a/apps/queue-worker/config.ts +++ b/apps/queue-worker/config.ts @@ -15,7 +15,9 @@ export const config = () => ({ }, services: { redis: { - url: process.env.REDIS_URL || '127.0.0.1', + host: process.env.REDIS_HOST || '127.0.0.1', + port: parseInt(process.env.REDIS_PORT || '6379'), + password: process.env.REDIS_PASSWORD, }, }, }) diff --git a/apps/queue-worker/src/main.ts b/apps/queue-worker/src/main.ts index a46b4b5..c3ebd7c 100644 --- a/apps/queue-worker/src/main.ts +++ b/apps/queue-worker/src/main.ts @@ -20,8 +20,9 @@ async function bootstrap() { const pubSubApp = await NestFactory.createMicroservice(PubSubListenerModule.forRoot(config), { transport: Transport.REDIS, options: { - host: appConfigService.redisUrl, - port: 6379, + host: appConfigService.redisHost, + port: appConfigService.redisPort, + password: appConfigService.redisPassword || undefined, retryAttempts: 100, retryDelay: 1000, retryStrategy: () => 1000, diff --git a/apps/queue-worker/src/worker/bull.queue.module.ts b/apps/queue-worker/src/worker/bull.queue.module.ts index 89f4012..ec025ff 100644 --- a/apps/queue-worker/src/worker/bull.queue.module.ts +++ b/apps/queue-worker/src/worker/bull.queue.module.ts @@ -8,8 +8,9 @@ import { AppConfigModule, AppConfigService } from '@mvx-monorepo/common' BullModule.forRootAsync({ useFactory: (appConfigService: AppConfigService) => ({ redis: { - host: appConfigService.redisUrl, - port: 6379, + host: appConfigService.redisHost, + port: appConfigService.redisPort, + password: appConfigService.redisPassword || undefined, }, }), imports: [AppConfigModule.forRoot(config)], diff --git a/apps/transactions-processor/config.ts b/apps/transactions-processor/config.ts index 1a493f1..86791dd 100644 --- a/apps/transactions-processor/config.ts +++ b/apps/transactions-processor/config.ts @@ -19,7 +19,9 @@ export const config = () => ({ apiUrl: process.env.CHAIN_API_URL || 'https://api.multiversx.com', }, redis: { - url: process.env.REDIS_URL || '127.0.0.1', + host: process.env.REDIS_HOST || '127.0.0.1', + port: parseInt(process.env.REDIS_PORT || '6379'), + password: process.env.REDIS_PASSWORD, }, }, }) diff --git a/apps/transactions-processor/src/main.ts b/apps/transactions-processor/src/main.ts index d54988f..b8c86f4 100644 --- a/apps/transactions-processor/src/main.ts +++ b/apps/transactions-processor/src/main.ts @@ -20,8 +20,9 @@ async function bootstrap() { const pubSubApp = await NestFactory.createMicroservice(PubSubListenerModule.forRoot(config), { transport: Transport.REDIS, options: { - host: appConfigService.redisUrl, - port: 6379, + host: appConfigService.redisHost, + port: appConfigService.redisPort, + password: appConfigService.redisPassword || undefined, retryAttempts: 100, retryDelay: 1000, retryStrategy: () => 1000, diff --git a/libs/common/src/config/app.config.service.ts b/libs/common/src/config/app.config.service.ts index 217d1ef..bf89cb6 100644 --- a/libs/common/src/config/app.config.service.ts +++ b/libs/common/src/config/app.config.service.ts @@ -28,22 +28,16 @@ export class AppConfigService { return this.configService.getOrThrow('services.swagger.urls') } - get redisUrl(): string { - return this.configService.getOrThrow('services.redis.url') - } - get redisHost(): string { - return this.redisUrl.split(':')[0] + return this.configService.getOrThrow('services.redis.host') } get redisPort(): number { - const components = this.redisUrl.split(':') - - if (components.length > 1) { - return Number(components[1]) - } + return this.configService.getOrThrow('services.redis.port') + } - return 6379 + get redisPassword(): string | null { + return this.configService.get('services.redis.password') || null } get isPublicApiFeatureActive(): boolean { diff --git a/libs/common/src/utils/dynamic.module.utils.ts b/libs/common/src/utils/dynamic.module.utils.ts index 6b52e0e..2a9435d 100644 --- a/libs/common/src/utils/dynamic.module.utils.ts +++ b/libs/common/src/utils/dynamic.module.utils.ts @@ -25,8 +25,9 @@ export class DynamicModuleUtils { useFactory: (appConfigService: AppConfigService) => new RedisCacheModuleOptions( { - host: appConfigService.redisUrl, + host: appConfigService.redisHost, port: appConfigService.redisPort, + password: appConfigService.redisPassword || undefined, }, { poolLimit: appConfigService.poolLimit, @@ -65,8 +66,9 @@ export class DynamicModuleUtils { const clientOptions: ClientOptions = { transport: Transport.REDIS, options: { - host: appConfigService.redisUrl, - port: 6379, + host: appConfigService.redisHost, + port: appConfigService.redisPort, + password: appConfigService.redisPassword || undefined, retryDelay: 1000, retryAttempts: 10, retryStrategy: () => 1000,