This commit is contained in:
pradeepkumar
2026-04-07 11:48:27 +05:30
parent c949b2d217
commit 44de2aeaa9
2 changed files with 16 additions and 5 deletions

View File

@@ -21,9 +21,15 @@ export class RedisIoAdapter extends IoAdapter {
const port = this.configService.get<number>('redis.port', 6379);
const password = this.configService.get<string>('redis.password') || undefined;
const db = this.configService.get<number>('redis.db', 0);
const useTls = process.env.REDIS_TLS === 'true';
const pubClient = new Redis({ host, port, password, db });
const subClient = new Redis({ host, port, password, db });
const opts: any = { host, port, password, db };
if (useTls) {
opts.tls = { rejectUnauthorized: false };
}
const pubClient = new Redis(opts);
const subClient = new Redis(opts);
pubClient.on('error', (err) => this.logger.error(`Redis pub error: ${err.message}`));
subClient.on('error', (err) => this.logger.error(`Redis sub error: ${err.message}`));

View File

@@ -6,16 +6,21 @@ export const REDIS_CLIENT = 'REDIS_CLIENT';
export const redisProvider = {
provide: REDIS_CLIENT,
useFactory: (configService: ConfigService) => {
const client = new Redis({
const useTls = process.env.REDIS_TLS === 'true';
const opts: any = {
host: configService.get<string>('redis.host', 'localhost'),
port: configService.get<number>('redis.port', 6379),
password: configService.get<string>('redis.password') || undefined,
db: configService.get<number>('redis.db', 0),
retryStrategy: (times: number) => {
if (times > 10) return null; // Stop retrying after 10 attempts
if (times > 10) return null;
return Math.min(times * 200, 2000);
},
});
};
if (useTls) {
opts.tls = { rejectUnauthorized: false };
}
const client = new Redis(opts);
client.on('connect', () => {
console.log('[Redis] Client connected');