Skip to content

Commit

Permalink
update redis configs
Browse files Browse the repository at this point in the history
  • Loading branch information
michavie committed Jan 9, 2024
1 parent a91a716 commit 94073de
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 28 deletions.
4 changes: 3 additions & 1 deletion apps/api/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
})
5 changes: 3 additions & 2 deletions apps/api/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ async function bootstrap() {
const pubSubApp = await NestFactory.createMicroservice<MicroserviceOptions>(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,
Expand Down
4 changes: 3 additions & 1 deletion apps/cache-warmer/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
})
5 changes: 3 additions & 2 deletions apps/cache-warmer/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ async function bootstrap() {
const pubSubApp = await NestFactory.createMicroservice<MicroserviceOptions>(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,
Expand Down
4 changes: 3 additions & 1 deletion apps/queue-worker/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
})
5 changes: 3 additions & 2 deletions apps/queue-worker/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ async function bootstrap() {
const pubSubApp = await NestFactory.createMicroservice<MicroserviceOptions>(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,
Expand Down
5 changes: 3 additions & 2 deletions apps/queue-worker/src/worker/bull.queue.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)],
Expand Down
4 changes: 3 additions & 1 deletion apps/transactions-processor/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
})
5 changes: 3 additions & 2 deletions apps/transactions-processor/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ async function bootstrap() {
const pubSubApp = await NestFactory.createMicroservice<MicroserviceOptions>(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,
Expand Down
16 changes: 5 additions & 11 deletions libs/common/src/config/app.config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,16 @@ export class AppConfigService {
return this.configService.getOrThrow<string[]>('services.swagger.urls')
}

get redisUrl(): string {
return this.configService.getOrThrow<string>('services.redis.url')
}

get redisHost(): string {
return this.redisUrl.split(':')[0]
return this.configService.getOrThrow<string>('services.redis.host')
}

get redisPort(): number {
const components = this.redisUrl.split(':')

if (components.length > 1) {
return Number(components[1])
}
return this.configService.getOrThrow<number>('services.redis.port')
}

return 6379
get redisPassword(): string | null {
return this.configService.get<string>('services.redis.password') || null
}

get isPublicApiFeatureActive(): boolean {
Expand Down
8 changes: 5 additions & 3 deletions libs/common/src/utils/dynamic.module.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 94073de

Please sign in to comment.