From 7c601fc28d708aadf5c3b30e9f05a13fa008ddde Mon Sep 17 00:00:00 2001 From: Ste Prescott Date: Wed, 9 Aug 2023 23:36:40 +0100 Subject: [PATCH] Allow for multiple nodes to be supplied as a string when creating a cluster --- lib/cluster/index.ts | 5 ++++- test/functional/cluster/connect.ts | 11 +++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/cluster/index.ts b/lib/cluster/index.ts index 8419b1a35..19f96d175 100644 --- a/lib/cluster/index.ts +++ b/lib/cluster/index.ts @@ -118,7 +118,10 @@ class Cluster extends Commander { super(); EventEmitter.call(this); - this.startupNodes = startupNodes; + this.startupNodes = startupNodes + ?.map((node) => (typeof node === 'string' ? node.split(',') : [node])) + .flat(); + this.options = defaults({}, options, DEFAULT_CLUSTER_OPTIONS, this.options); if ( diff --git a/test/functional/cluster/connect.ts b/test/functional/cluster/connect.ts index a2346f23e..783bc53cf 100644 --- a/test/functional/cluster/connect.ts +++ b/test/functional/cluster/connect.ts @@ -119,6 +119,17 @@ describe("cluster:connect", () => { }); }); + it("should support url schema with mutiple nodes", (done) => { + const node = new MockServer(30001); + + const cluster = new Cluster([30002, "127.0.0.4:30001", { host:"127.0.0.3", port: 30001 }, "redis://127.0.0.2:30001,127.0.0.1:30001"]); + + node.once("connect", () => { + cluster.disconnect(); + done(); + }); + }); + it("should support a single port", (done) => { const node = new MockServer(30001);