Skip to content

Commit

Permalink
Added redis.db config, added output for connections
Browse files Browse the repository at this point in the history
  • Loading branch information
Maelstromeous committed Apr 28, 2023
1 parent 291bfad commit 7271d8a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@ export const config = () => ({
host: env('REDIS_HOST', 'ps2alerts-redis'),
port: envInt('REDIS_PORT', 10, 6379),
password: env('REDIS_PASS', ''),
db: env('REDIS_DB', 0),
},
});
23 changes: 18 additions & 5 deletions src/modules/redis/RedisModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,24 @@ import {ConfigService} from '@nestjs/config';
providers: [
{
provide: Redis,
useFactory: (config: ConfigService) => new Redis({
host: config.get('redis.host'),
port: config.get('redis.port'),
password: config.get('redis.password'),
}),
useFactory: (config: ConfigService) => {
const redisHost: string = config.get('redis.host');
const redisPort: number = config.get('redis.port');
const redisPass: string = config.get('redis.password');
const redisDb: number = config.get('redis.db');

console.log(`Connecting to Redis: ${redisHost}:${redisPort}:${redisPass}[${redisDb}]`);

const redis = new Redis({
host: redisHost,
port: redisPort,
password: redisPass,
db: redisDb,
});

console.log('Connected to Redis!');
return redis;
},
inject: [ConfigService],
},
],
Expand Down

0 comments on commit 7271d8a

Please sign in to comment.