Open engmsilva opened 1 year ago
For anyone experiencing the same problem, here's the change I made to the connection file to be able to use redis with sentinel.
import { Injectable } from '@nestjs/common';
import {
RedisOptionsFactory,
RedisModuleOptions,
} from '@liaoliaots/nestjs-redis';
import { InjectPinoLogger } from 'nestjs-pino/InjectPinoLogger';
import { PinoLogger } from 'nestjs-pino';
export interface ErrnoException extends Error {
errno?: number;
code?: string;
path?: string;
syscall?: string;
stack?: string;
}
@Injectable()
export class RedisConfigService implements RedisOptionsFactory {
constructor(
@InjectPinoLogger(RedisConfigService.name)
private readonly logger: PinoLogger,
) {}
async createRedisOptions(): Promise<RedisModuleOptions> {
const logger = this.logger;
return {
readyLog: true,
commonOptions: {
name: process.env.REDIS_SENTINEL_MASTER,
sentinels: [
{
host: process.env.REDIS_SENTINEL_01,
port: parseInt(process.env.REDIS_SENTINEL_PORT),
},
{
host: process.env.REDIS_SENTINEL_02,
port: parseInt(process.env.REDIS_SENTINEL_PORT),
},
{
host: process.env.REDIS_SENTINEL_03,
port: parseInt(process.env.REDIS_SENTINEL_PORT),
},
],
},
config: [
{
role: 'master',
password: process.env.REDIS_PASSWORD,
maxRetriesPerRequest: 0,
onClientCreated(client) {
client.on('error', (error: ErrnoException) => {
logger.info(
{ description: '[Create Conection][Error]' },
JSON.stringify(error),
);
});
},
retryStrategy(times) {
const delay = Math.min(times * 50, 2000);
return delay;
},
},
],
};
}
}
My application works correctly accessing only one instance of Redis, but I am not able to configure my application with Redis Sentinel.
I tried to follow the example of the project's repositories, but it seems that nothing happens.
My module looks like this:
My connection configuration file looks like this:
Are these my Redis and Sentinel servers?
What would be the best way to adapt the code above to connect with Redis sentinel?