Skip to content

Commit c03c34f

Browse files
committed
fix redis sentinel failover
1 parent e72a489 commit c03c34f

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

packages/client/lib/sentinel/index.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,16 @@ class RedisSentinelInternal<
928928
}
929929
}
930930

931+
#handleSentinelFailure(node: RedisNode) {
932+
const found = this.#sentinelRootNodes.findIndex(
933+
(rootNode) => rootNode.host === node.host && rootNode.port === node.port
934+
);
935+
if (found !== -1) {
936+
this.#sentinelRootNodes.splice(found, 1);
937+
}
938+
this.#reset();
939+
}
940+
931941
async close() {
932942
this.#destroy = true;
933943

@@ -1197,8 +1207,9 @@ class RedisSentinelInternal<
11971207
error: err
11981208
};
11991209
this.emit('client-error', event);
1200-
this.#reset();
1201-
});
1210+
this.#handleSentinelFailure(node);
1211+
})
1212+
.on('end', () => this.#handleSentinelFailure(node));
12021213
this.#sentinelClient = client;
12031214

12041215
this.#trace(`transform: adding sentinel client connect() to promise list`);

0 commit comments

Comments
 (0)