Skip to content

Commit

Permalink
Updated Sentinel options to ensure failoverDetector and sentinel retr…
Browse files Browse the repository at this point in the history
…y strategy
  • Loading branch information
troll-os committed Jun 2, 2024
1 parent af06909 commit c6a6a4d
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions opencti-platform/opencti-graphql/src/database/redis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,13 @@ const sentinelOptions = async (clusterNodes: Partial<SentinelAddress>[]): Promis
preferredSlaves: conf.get('redis:sentinel_preferred_slaves'),
sentinels: clusterNodes,
enableTLSForSentinelMode: conf.get('redis:sentinel_tls') ?? false,
failoverDetector: true,
sentinelRetryStrategy: (times: number) => {
return Math.min(times * 10, 1000);
}
};
};

export const reconnectOnError = (error: any) => {
const targetError = 'READONLY';
// Only reconnect when the error starts with "READONLY"
return error.message.slice(0, targetError.length) === targetError;
};

export const createRedisClient = async (provider: string, autoReconnect = false): Promise<Cluster | Redis> => {
let client: Cluster | Redis;
const redisMode: string = conf.get('redis:mode');
Expand All @@ -126,10 +124,10 @@ export const createRedisClient = async (provider: string, autoReconnect = false)
client = new Redis.Cluster(clusterNodes, clusterOpts);
} else if (redisMode === 'sentinel') {
const sentinelOpts = await sentinelOptions(clusterNodes);
client = new Redis({ ...sentinelOpts, reconnectOnError });
client = new Redis(sentinelOpts);
} else {
const singleOptions = await redisOptions(autoReconnect);
client = new Redis({ ...singleOptions, port: conf.get('redis:port'), host: conf.get('redis:hostname'), reconnectOnError });
client = new Redis({ ...singleOptions, port: conf.get('redis:port'), host: conf.get('redis:hostname') });
}

client.on('close', () => logApp.info(`[REDIS] Redis '${provider}' client closed`));
Expand Down

0 comments on commit c6a6a4d

Please sign in to comment.