Skip to content

Duplcatet masters in RedisClusterSlots #2991

Closed
@maciomen

Description

@maciomen

Description

Hi,

Thanks for the great work on this library!

I believe there might be an issue with how the masters array is populated in RedisClusterSlots. Consider this scenario:

Let’s assume I have a cluster with 300 max slots. If:

  • node-1 owns slots 0–100 and 200–300

  • node-2 owns slots 101–199

Then client.clusterSlots() will return three entries—two of them for node-1 with different from/to ranges.

When iterating over this result to populate the masters array, node-1 appears twice. This leads to the masters array having 3 entries instead of the expected 2 (i.e., node-1 and node-2 only once each).

Here’s a minimal example:

const cluster = createCluster(...);
await cluster.connect();
console.log(cluster.masters.length); // Outputs 3 instead of 2

Is this the expected behavior? Or should masters deduplicate entries by host/port or id?

Thanks in advance for clarifying!

Node.js Version

v22.14.0

Redis Server Version

7.2.4

Node Redis Version

4.7.1

Platform

Linux

Logs

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions