Skip to content

CLUSTER SHARDS#431

Merged
alicebob merged 4 commits intomasterfrom
shards
Jan 22, 2026
Merged

CLUSTER SHARDS#431
alicebob merged 4 commits intomasterfrom
shards

Conversation

@alicebob
Copy link
Owner

for #430

@alicebob alicebob self-assigned this Jan 21, 2026
@alicebob alicebob changed the title CLUSTER CHARDS CLUSTER SHARDS Jan 21, 2026
@dadrus
Copy link
Contributor

dadrus commented Jan 21, 2026

It looks like the cmdClusterShards implementation is incomplete. I now get "the slot has no redis node" as error. I would really like to support, but I don't understand how the redis commands are structured.

If it helps, clone https://github.com/dadrus/heimdall, switch to the branch from dadrus/heimdall#2992 PR, replace the miniredis dependency to your version and run https://github.com/dadrus/heimdall/blob/c1da7b6dc5b488da3e14e67943f174f60858ddee/internal/cache/redis/cluster_test.go#L46 tests. "successful cache creation with TLS" and "successful cache creation without TLS" are those which fail in that branch

@alicebob
Copy link
Owner Author

Thanks for your feedback! I see you use github.com/redis/rueidis as a client, so I should be able to test that. Won't have time for this tomorrow, so you should pin the previous version for now.

@dadrus
Copy link
Contributor

dadrus commented Jan 21, 2026

I used some help of chatgpt and it worked with the following update:

// CLUSTER SHARDS
func (m *Miniredis) cmdClusterShards(c *server.Peer, cmd string, args []string) {
	withTx(m, c, func(c *server.Peer, ctx *connCtx) {
		addr := m.srv.Addr()
		host := addr.IP.String()
		port := addr.Port

		// Array of shards (we return 1 shard)
		c.WriteLen(1)

		// Shard is a map with 2 keys: "slots" and "nodes"
		c.WriteMapLen(2)

		// "slots": flat list of start/end pairs (inclusive ranges)
		c.WriteBulk("slots")
		c.WriteLen(2)
		c.WriteInt(0)
		c.WriteInt(16383)

		// "nodes": array of node maps
		c.WriteBulk("nodes")
		c.WriteLen(1)

		// Node map.
		// (id, endpoint, ip, port, role, replication-offset, health)
		c.WriteMapLen(6)

		c.WriteBulk("id")
		c.WriteBulk("13f84e686106847b76671957dd348fde540a77bb")

		//c.WriteBulk("endpoint")
		//c.WriteBulk(host) // or host:port if your client expects that

		c.WriteBulk("ip")
		c.WriteBulk(host)

		c.WriteBulk("port")
		c.WriteInt(port)

		c.WriteBulk("role")
		c.WriteBulk("master")

		c.WriteBulk("replication-offset")
		c.WriteInt(0)

		c.WriteBulk("health")
		c.WriteBulk("online")
	})
}

Though, I'm not sure, whether there are some edge cases. I'll push an update to your PR, so you can review

@dadrus
Copy link
Contributor

dadrus commented Jan 21, 2026

update is pending in #432

@alicebob alicebob merged commit 7ae63ba into master Jan 22, 2026
4 checks passed
@alicebob
Copy link
Owner Author

I used what my redis here returned, but if this works for you, then that should be enough. I merged this to master, will make a new release tomorrow.

@alicebob alicebob deleted the shards branch January 22, 2026 07:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants