Skip to content

Commit 3eede3c

Browse files
authored
Better handle redis error events (#1652)
1 parent b3afbcf commit 3eede3c

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

apps/webapp/app/redis.server.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ export function createRedisClient(
1818
connectionName: string,
1919
options: RedisWithClusterOptions
2020
): Redis | Cluster {
21+
let redis: Redis | Cluster;
22+
2123
if (options.clusterMode) {
2224
const nodes: ClusterNode[] = [
2325
{
@@ -32,7 +34,7 @@ export function createRedisClient(
3234
port: options.port,
3335
});
3436

35-
return new Redis.Cluster(nodes, {
37+
redis = new Redis.Cluster(nodes, {
3638
...options.clusterOptions,
3739
redisOptions: {
3840
connectionName,
@@ -59,7 +61,7 @@ export function createRedisClient(
5961
port: options.port,
6062
});
6163

62-
return new Redis({
64+
redis = new Redis({
6365
connectionName,
6466
host: options.host,
6567
port: options.port,
@@ -69,4 +71,10 @@ export function createRedisClient(
6971
...(options.tlsDisabled ? {} : { tls: {} }),
7072
});
7173
}
74+
75+
redis.on("error", (error) => {
76+
logger.error("Redis client error", { connectionName, error });
77+
});
78+
79+
return redis;
7280
}

0 commit comments

Comments
 (0)