Skip to content

Commit 25d2816

Browse files
committed
CLUSTER SHARDS
1 parent 99437e6 commit 25d2816

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

cmd_cluster.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ func (m *Miniredis) cmdCluster(c *server.Peer, cmd string, args []string) {
3131
m.cmdClusterKeySlot(c, cmd, args)
3232
case "NODES":
3333
m.cmdClusterNodes(c, cmd, args)
34+
case "SHARDS":
35+
m.cmdClusterShards(c, cmd, args)
3436
default:
3537
setDirty(c)
3638
c.WriteError(fmt.Sprintf("ERR 'CLUSTER %s' not supported", strings.Join(args, " ")))
@@ -68,3 +70,32 @@ func (m *Miniredis) cmdClusterNodes(c *server.Peer, cmd string, args []string) {
6870
c.WriteBulk(fmt.Sprintf("e7d1eecce10fd6bb5eb35b9f99a514335d9ba9ca %s@%d myself,master - 0 0 1 connected 0-16383", addr, port))
6971
})
7072
}
73+
74+
// CLUSTER SHARDS
75+
func (m *Miniredis) cmdClusterShards(c *server.Peer, cmd string, args []string) {
76+
withTx(m, c, func(c *server.Peer, ctx *connCtx) {
77+
// addr := m.srv.Addr()
78+
port := m.srv.Addr().Port
79+
c.WriteLen(1)
80+
c.WriteMapLen(2)
81+
c.WriteBulk("slots")
82+
c.WriteLen(0)
83+
c.WriteBulk("nodes")
84+
c.WriteLen(1)
85+
c.WriteMapLen(7)
86+
c.WriteBulk("id")
87+
c.WriteBulk("13f84e686106847b76671957dd348fde540a77bb")
88+
c.WriteBulk("port")
89+
c.WriteInt(port)
90+
c.WriteBulk("ip")
91+
c.WriteBulk("")
92+
c.WriteBulk("endpoint")
93+
c.WriteBulk("")
94+
c.WriteBulk("role")
95+
c.WriteBulk("master")
96+
c.WriteBulk("replication-offset")
97+
c.WriteInt(0)
98+
c.WriteBulk("health")
99+
c.WriteBulk("online")
100+
})
101+
}

cmd_cluster_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,35 @@ func TestCluster(t *testing.T) {
3838
)
3939
})
4040

41+
t.Run("shards", func(t *testing.T) {
42+
mustDo(t, c,
43+
"CLUSTER", "SHARDS",
44+
proto.Array(
45+
proto.Array(
46+
proto.String("slots"), proto.Array(),
47+
proto.String("nodes"), proto.Array(
48+
proto.Array(
49+
proto.String("id"),
50+
proto.String("13f84e686106847b76671957dd348fde540a77bb"),
51+
proto.String("port"),
52+
proto.Int(s.srv.Addr().Port),
53+
proto.String("ip"),
54+
proto.String(""),
55+
proto.String("endpoint"),
56+
proto.String(""),
57+
proto.String("role"),
58+
proto.String("master"),
59+
proto.String("replication-offset"),
60+
proto.Int(0),
61+
proto.String("health"),
62+
proto.String("online"),
63+
),
64+
),
65+
),
66+
),
67+
)
68+
})
69+
4170
t.Run("keyslot", func(t *testing.T) {
4271
mustDo(t, c,
4372
"CLUSTER", "keyslot", "{test_key}",

integration/cluster_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ func TestCluster(t *testing.T) {
1010
c.DoLoosely("CLUSTER", "KEYSLOT", "{test}")
1111
c.DoLoosely("CLUSTER", "NODES")
1212
c.Error("wrong number", "CLUSTER")
13+
c.DoLoosely("CLUSTER", "SHARDS")
1314
},
1415
)
1516
}

0 commit comments

Comments
 (0)