Skip to content

Commit ef7bb4a

Browse files
committed
Include nodeId in key in cluster connectionpool, correctly refreshing connections when nodeId changes
Fixes #1778
1 parent 9c17550 commit ef7bb4a

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

lib/cluster/ConnectionPool.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export default class ConnectionPool extends EventEmitter {
4040
* Find or create a connection to the node
4141
*/
4242
findOrCreate(node: RedisOptions, readOnly = false): Redis {
43-
const key = getNodeKey(node);
43+
const key = this.getNodeKey(node);
4444
readOnly = Boolean(readOnly);
4545

4646
if (this.specifiedOptions[key]) {
@@ -113,7 +113,7 @@ export default class ConnectionPool extends EventEmitter {
113113
debug("Reset with %O", nodes);
114114
const newNodes = {};
115115
nodes.forEach((node) => {
116-
const key = getNodeKey(node);
116+
const key = this.getNodeKey(node);
117117

118118
// Don't override the existing (master) node
119119
// when the current one is slave.
@@ -147,4 +147,8 @@ export default class ConnectionPool extends EventEmitter {
147147
delete nodes.master[key];
148148
delete nodes.slave[key];
149149
}
150+
151+
private getNodeKey(options: RedisOptions) {
152+
return getNodeKey(options) + ':' + options.nodeId;
153+
}
150154
}

lib/cluster/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,7 @@ class Cluster extends Commander {
864864
port: items[j][1],
865865
});
866866
node.readOnly = j !== 2;
867+
node.nodeId = items[j][2];
867868
nodes.push(node);
868869
keys.push(node.host + ":" + node.port);
869870
}

lib/cluster/util.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export interface RedisOptions {
1010
host: string;
1111
username?: string;
1212
password?: string;
13+
nodeId?: string;
1314
[key: string]: any;
1415
}
1516

0 commit comments

Comments
 (0)