diff --git a/lib/cluster/ConnectionPool.ts b/lib/cluster/ConnectionPool.ts index dbab62c9..f6f83ea2 100644 --- a/lib/cluster/ConnectionPool.ts +++ b/lib/cluster/ConnectionPool.ts @@ -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]) { @@ -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. @@ -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; + } } diff --git a/lib/cluster/index.ts b/lib/cluster/index.ts index 8419b1a3..9a514c0e 100644 --- a/lib/cluster/index.ts +++ b/lib/cluster/index.ts @@ -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); } diff --git a/lib/cluster/util.ts b/lib/cluster/util.ts index 4b12b955..b00ba6a0 100644 --- a/lib/cluster/util.ts +++ b/lib/cluster/util.ts @@ -10,6 +10,7 @@ export interface RedisOptions { host: string; username?: string; password?: string; + nodeId?: string; [key: string]: any; }