Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include nodeId in key in cluster connectionpool, correctly refreshing connections when nodeId changes #1779

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/cluster/ConnectionPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default class ConnectionPool extends EventEmitter {
* Find or create a connection to the node
*/
findOrCreate(node: RedisOptions, readOnly = false): Redis {
const key = getNodeKey(node);
const key = this.getNodeKey(node);
readOnly = Boolean(readOnly);

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

// Don't override the existing (master) node
// when the current one is slave.
Expand Down Expand Up @@ -147,4 +147,8 @@ export default class ConnectionPool extends EventEmitter {
delete nodes.master[key];
delete nodes.slave[key];
}

private getNodeKey(options: RedisOptions) {
return getNodeKey(options) + ':' + options.nodeId;
}
}
1 change: 1 addition & 0 deletions lib/cluster/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,7 @@ class Cluster extends Commander {
port: items[j][1],
});
node.readOnly = j !== 2;
node.nodeId = items[j][2];
nodes.push(node);
keys.push(node.host + ":" + node.port);
}
Expand Down
1 change: 1 addition & 0 deletions lib/cluster/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface RedisOptions {
host: string;
username?: string;
password?: string;
nodeId?: string;
[key: string]: any;
}

Expand Down