fix
This commit is contained in:
@@ -21,9 +21,15 @@ export class RedisIoAdapter extends IoAdapter {
|
|||||||
const port = this.configService.get<number>('redis.port', 6379);
|
const port = this.configService.get<number>('redis.port', 6379);
|
||||||
const password = this.configService.get<string>('redis.password') || undefined;
|
const password = this.configService.get<string>('redis.password') || undefined;
|
||||||
const db = this.configService.get<number>('redis.db', 0);
|
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 opts: any = { host, port, password, db };
|
||||||
const subClient = new Redis({ 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}`));
|
pubClient.on('error', (err) => this.logger.error(`Redis pub error: ${err.message}`));
|
||||||
subClient.on('error', (err) => this.logger.error(`Redis sub error: ${err.message}`));
|
subClient.on('error', (err) => this.logger.error(`Redis sub error: ${err.message}`));
|
||||||
|
|||||||
@@ -6,16 +6,21 @@ export const REDIS_CLIENT = 'REDIS_CLIENT';
|
|||||||
export const redisProvider = {
|
export const redisProvider = {
|
||||||
provide: REDIS_CLIENT,
|
provide: REDIS_CLIENT,
|
||||||
useFactory: (configService: ConfigService) => {
|
useFactory: (configService: ConfigService) => {
|
||||||
const client = new Redis({
|
const useTls = process.env.REDIS_TLS === 'true';
|
||||||
|
const opts: any = {
|
||||||
host: configService.get<string>('redis.host', 'localhost'),
|
host: configService.get<string>('redis.host', 'localhost'),
|
||||||
port: configService.get<number>('redis.port', 6379),
|
port: configService.get<number>('redis.port', 6379),
|
||||||
password: configService.get<string>('redis.password') || undefined,
|
password: configService.get<string>('redis.password') || undefined,
|
||||||
db: configService.get<number>('redis.db', 0),
|
db: configService.get<number>('redis.db', 0),
|
||||||
retryStrategy: (times: number) => {
|
retryStrategy: (times: number) => {
|
||||||
if (times > 10) return null; // Stop retrying after 10 attempts
|
if (times > 10) return null;
|
||||||
return Math.min(times * 200, 2000);
|
return Math.min(times * 200, 2000);
|
||||||
},
|
},
|
||||||
});
|
};
|
||||||
|
if (useTls) {
|
||||||
|
opts.tls = { rejectUnauthorized: false };
|
||||||
|
}
|
||||||
|
const client = new Redis(opts);
|
||||||
|
|
||||||
client.on('connect', () => {
|
client.on('connect', () => {
|
||||||
console.log('[Redis] Client connected');
|
console.log('[Redis] Client connected');
|
||||||
|
|||||||
Reference in New Issue
Block a user