Skip to content

Commit

Permalink
Better handle redis error events (#1652)
Browse files Browse the repository at this point in the history
  • Loading branch information
ericallam authored Jan 29, 2025
1 parent b3afbcf commit 3eede3c
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions apps/webapp/app/redis.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export function createRedisClient(
connectionName: string,
options: RedisWithClusterOptions
): Redis | Cluster {
let redis: Redis | Cluster;

if (options.clusterMode) {
const nodes: ClusterNode[] = [
{
Expand All @@ -32,7 +34,7 @@ export function createRedisClient(
port: options.port,
});

return new Redis.Cluster(nodes, {
redis = new Redis.Cluster(nodes, {
...options.clusterOptions,
redisOptions: {
connectionName,
Expand All @@ -59,7 +61,7 @@ export function createRedisClient(
port: options.port,
});

return new Redis({
redis = new Redis({
connectionName,
host: options.host,
port: options.port,
Expand All @@ -69,4 +71,10 @@ export function createRedisClient(
...(options.tlsDisabled ? {} : { tls: {} }),
});
}

redis.on("error", (error) => {
logger.error("Redis client error", { connectionName, error });
});

return redis;
}

0 comments on commit 3eede3c

Please sign in to comment.