From f119f684b3e5095ba9c669e786d1a52ea42bbb9f Mon Sep 17 00:00:00 2001 From: Rueian Date: Mon, 2 Sep 2024 23:00:00 +0800 Subject: [PATCH] feat: add SCRIPT SHOW, CLIENT CAPA, and CLUSTER SLOT-STATS commands (#628) Signed-off-by: Rueian --- hack/cmds/commands.json | 100 ++++++++++++++++++++ internal/cmds/gen_cluster.go | 131 +++++++++++++++++++++++++++ internal/cmds/gen_cluster_test.go | 12 +++ internal/cmds/gen_connection.go | 25 +++++ internal/cmds/gen_connection_test.go | 3 +- internal/cmds/gen_scripting.go | 20 ++++ internal/cmds/gen_scripting_test.go | 1 + internal/cmds/gen_sorted_set.go | 22 +++++ internal/cmds/gen_sorted_set_test.go | 3 + 9 files changed, 316 insertions(+), 1 deletion(-) diff --git a/hack/cmds/commands.json b/hack/cmds/commands.json index 7c43c09f..2815c726 100644 --- a/hack/cmds/commands.json +++ b/hack/cmds/commands.json @@ -636,6 +636,17 @@ "since": "6.0.0", "group": "connection" }, + "CLIENT CAPA": { + "arguments": [ + { + "name": "capability", + "type": "string", + "multiple": true + } + ], + "since": "8.0.0", + "group": "connection" + }, "CLIENT GETNAME": { "summary": "Get the current connection name", "complexity": "O(1)", @@ -1242,6 +1253,12 @@ "name": "node-id", "type": "string", "optional": true + }, + { + "name": "timeout", + "command": "TIMEOUT", + "type": "integer", + "optional": true } ], "since": "3.0.0", @@ -1268,6 +1285,73 @@ "since": "3.0.0", "group": "cluster" }, + "CLUSTER SLOT-STATS": { + "arguments": [ + { + "name": "filter", + "type": "oneof", + "arguments": [ + { + "type": "block", + "arguments": [ + { + "token": "SLOTSRANGE", + "type": "pure-token", + "name": "slotsrange" + }, + { + "name": "start-slot", + "type": "integer" + }, + { + "name": "end-slot", + "type": "integer" + } + ] + }, + { + "type": "block", + "arguments": [ + { + "token": "ORDERBY", + "type": "pure-token", + "name": "orderby" + }, + { + "name": "metric", + "type": "string" + }, + { + "token": "LIMIT", + "name": "limit", + "type": "integer", + "optional": true + }, + { + "name": "order", + "type": "oneof", + "optional": true, + "arguments": [ + { + "name": "asc", + "type": "pure-token", + "token": "ASC" + }, + { + "name": "desc", + "type": "pure-token", + "token": "DESC" + } + ] + } + ] + } + ] + } + ], + "since": "8.0.0", + "group": "cluster" + }, "COMMAND COUNT": { "summary": "Get total number of Redis commands", "complexity": "O(1)", @@ -4866,6 +4950,16 @@ "since": "2.6.0", "group": "scripting" }, + "SCRIPT SHOW": { + "arguments": [ + { + "name": "sha1", + "type": "string" + } + ], + "since": "8.0.0", + "group": "scripting" + }, "SCRIPT FLUSH": { "summary": "Remove all the scripts from the script cache.", "arguments": [ @@ -7228,6 +7322,12 @@ "name": "count", "type": "integer", "optional": true + }, + { + "token": "NOSCORES", + "name": "noscores", + "type": "pure-token", + "optional": true } ], "since": "2.8.0", diff --git a/internal/cmds/gen_cluster.go b/internal/cmds/gen_cluster.go index 83ef5e82..5c474ec5 100644 --- a/internal/cmds/gen_cluster.go +++ b/internal/cmds/gen_cluster.go @@ -522,6 +522,11 @@ func (c ClusterSetslot) Slot(slot int64) ClusterSetslotSlot { type ClusterSetslotNodeId Incomplete +func (c ClusterSetslotNodeId) Timeout(timeout int64) ClusterSetslotTimeout { + c.cs.s = append(c.cs.s, "TIMEOUT", strconv.FormatInt(timeout, 10)) + return (ClusterSetslotTimeout)(c) +} + func (c ClusterSetslotNodeId) Build() Completed { c.cs.Build() return Completed{cs: c.cs, cf: uint16(c.cf), ks: c.ks} @@ -556,6 +561,11 @@ func (c ClusterSetslotSubcommandImporting) NodeId(nodeId string) ClusterSetslotN return (ClusterSetslotNodeId)(c) } +func (c ClusterSetslotSubcommandImporting) Timeout(timeout int64) ClusterSetslotTimeout { + c.cs.s = append(c.cs.s, "TIMEOUT", strconv.FormatInt(timeout, 10)) + return (ClusterSetslotTimeout)(c) +} + func (c ClusterSetslotSubcommandImporting) Build() Completed { c.cs.Build() return Completed{cs: c.cs, cf: uint16(c.cf), ks: c.ks} @@ -568,6 +578,11 @@ func (c ClusterSetslotSubcommandMigrating) NodeId(nodeId string) ClusterSetslotN return (ClusterSetslotNodeId)(c) } +func (c ClusterSetslotSubcommandMigrating) Timeout(timeout int64) ClusterSetslotTimeout { + c.cs.s = append(c.cs.s, "TIMEOUT", strconv.FormatInt(timeout, 10)) + return (ClusterSetslotTimeout)(c) +} + func (c ClusterSetslotSubcommandMigrating) Build() Completed { c.cs.Build() return Completed{cs: c.cs, cf: uint16(c.cf), ks: c.ks} @@ -580,6 +595,11 @@ func (c ClusterSetslotSubcommandNode) NodeId(nodeId string) ClusterSetslotNodeId return (ClusterSetslotNodeId)(c) } +func (c ClusterSetslotSubcommandNode) Timeout(timeout int64) ClusterSetslotTimeout { + c.cs.s = append(c.cs.s, "TIMEOUT", strconv.FormatInt(timeout, 10)) + return (ClusterSetslotTimeout)(c) +} + func (c ClusterSetslotSubcommandNode) Build() Completed { c.cs.Build() return Completed{cs: c.cs, cf: uint16(c.cf), ks: c.ks} @@ -592,11 +612,23 @@ func (c ClusterSetslotSubcommandStable) NodeId(nodeId string) ClusterSetslotNode return (ClusterSetslotNodeId)(c) } +func (c ClusterSetslotSubcommandStable) Timeout(timeout int64) ClusterSetslotTimeout { + c.cs.s = append(c.cs.s, "TIMEOUT", strconv.FormatInt(timeout, 10)) + return (ClusterSetslotTimeout)(c) +} + func (c ClusterSetslotSubcommandStable) Build() Completed { c.cs.Build() return Completed{cs: c.cs, cf: uint16(c.cf), ks: c.ks} } +type ClusterSetslotTimeout Incomplete + +func (c ClusterSetslotTimeout) Build() Completed { + c.cs.Build() + return Completed{cs: c.cs, cf: uint16(c.cf), ks: c.ks} +} + type ClusterShards Incomplete func (b Builder) ClusterShards() (c ClusterShards) { @@ -630,6 +662,105 @@ func (c ClusterSlavesNodeId) Build() Completed { return Completed{cs: c.cs, cf: uint16(c.cf), ks: c.ks} } +type ClusterSlotStats Incomplete + +func (b Builder) ClusterSlotStats() (c ClusterSlotStats) { + c = ClusterSlotStats{cs: get(), ks: b.ks} + c.cs.s = append(c.cs.s, "CLUSTER", "SLOT-STATS") + return c +} + +func (c ClusterSlotStats) Slotsrange() ClusterSlotStatsFilterSlotsrangeSlotsrange { + c.cs.s = append(c.cs.s, "SLOTSRANGE") + return (ClusterSlotStatsFilterSlotsrangeSlotsrange)(c) +} + +func (c ClusterSlotStats) Orderby() ClusterSlotStatsFilterOrderbyOrderby { + c.cs.s = append(c.cs.s, "ORDERBY") + return (ClusterSlotStatsFilterOrderbyOrderby)(c) +} + +type ClusterSlotStatsFilterOrderbyLimit Incomplete + +func (c ClusterSlotStatsFilterOrderbyLimit) Asc() ClusterSlotStatsFilterOrderbyOrderAsc { + c.cs.s = append(c.cs.s, "ASC") + return (ClusterSlotStatsFilterOrderbyOrderAsc)(c) +} + +func (c ClusterSlotStatsFilterOrderbyLimit) Desc() ClusterSlotStatsFilterOrderbyOrderDesc { + c.cs.s = append(c.cs.s, "DESC") + return (ClusterSlotStatsFilterOrderbyOrderDesc)(c) +} + +func (c ClusterSlotStatsFilterOrderbyLimit) Build() Completed { + c.cs.Build() + return Completed{cs: c.cs, cf: uint16(c.cf), ks: c.ks} +} + +type ClusterSlotStatsFilterOrderbyMetric Incomplete + +func (c ClusterSlotStatsFilterOrderbyMetric) Limit(limit int64) ClusterSlotStatsFilterOrderbyLimit { + c.cs.s = append(c.cs.s, strconv.FormatInt(limit, 10)) + return (ClusterSlotStatsFilterOrderbyLimit)(c) +} + +func (c ClusterSlotStatsFilterOrderbyMetric) Asc() ClusterSlotStatsFilterOrderbyOrderAsc { + c.cs.s = append(c.cs.s, "ASC") + return (ClusterSlotStatsFilterOrderbyOrderAsc)(c) +} + +func (c ClusterSlotStatsFilterOrderbyMetric) Desc() ClusterSlotStatsFilterOrderbyOrderDesc { + c.cs.s = append(c.cs.s, "DESC") + return (ClusterSlotStatsFilterOrderbyOrderDesc)(c) +} + +func (c ClusterSlotStatsFilterOrderbyMetric) Build() Completed { + c.cs.Build() + return Completed{cs: c.cs, cf: uint16(c.cf), ks: c.ks} +} + +type ClusterSlotStatsFilterOrderbyOrderAsc Incomplete + +func (c ClusterSlotStatsFilterOrderbyOrderAsc) Build() Completed { + c.cs.Build() + return Completed{cs: c.cs, cf: uint16(c.cf), ks: c.ks} +} + +type ClusterSlotStatsFilterOrderbyOrderDesc Incomplete + +func (c ClusterSlotStatsFilterOrderbyOrderDesc) Build() Completed { + c.cs.Build() + return Completed{cs: c.cs, cf: uint16(c.cf), ks: c.ks} +} + +type ClusterSlotStatsFilterOrderbyOrderby Incomplete + +func (c ClusterSlotStatsFilterOrderbyOrderby) Metric(metric string) ClusterSlotStatsFilterOrderbyMetric { + c.cs.s = append(c.cs.s, metric) + return (ClusterSlotStatsFilterOrderbyMetric)(c) +} + +type ClusterSlotStatsFilterSlotsrangeEndSlot Incomplete + +func (c ClusterSlotStatsFilterSlotsrangeEndSlot) Build() Completed { + c.cs.Build() + return Completed{cs: c.cs, cf: uint16(c.cf), ks: c.ks} +} + +type ClusterSlotStatsFilterSlotsrangeSlotsrange Incomplete + +func (c ClusterSlotStatsFilterSlotsrangeSlotsrange) StartSlot(startSlot int64) ClusterSlotStatsFilterSlotsrangeStartSlot { + c.cs.s = append(c.cs.s, strconv.FormatInt(startSlot, 10)) + return (ClusterSlotStatsFilterSlotsrangeStartSlot)(c) +} + +type ClusterSlotStatsFilterSlotsrangeStartSlot Incomplete + +func (c ClusterSlotStatsFilterSlotsrangeStartSlot) EndSlot(endSlot int64) ClusterSlotStatsFilterSlotsrangeEndSlot { + c.cs.s = append(c.cs.s, strconv.FormatInt(endSlot, 10)) + return (ClusterSlotStatsFilterSlotsrangeEndSlot)(c) +} + type ClusterSlots Incomplete func (b Builder) ClusterSlots() (c ClusterSlots) { diff --git a/internal/cmds/gen_cluster_test.go b/internal/cmds/gen_cluster_test.go index 38992357..7be9a681 100644 --- a/internal/cmds/gen_cluster_test.go +++ b/internal/cmds/gen_cluster_test.go @@ -34,16 +34,28 @@ func cluster0(s Builder) { s.ClusterReset().Build() s.ClusterSaveconfig().Build() s.ClusterSetConfigEpoch().ConfigEpoch(1).Build() + s.ClusterSetslot().Slot(1).Importing().NodeId("1").Timeout(1).Build() s.ClusterSetslot().Slot(1).Importing().NodeId("1").Build() + s.ClusterSetslot().Slot(1).Importing().Timeout(1).Build() s.ClusterSetslot().Slot(1).Importing().Build() s.ClusterSetslot().Slot(1).Migrating().NodeId("1").Build() + s.ClusterSetslot().Slot(1).Migrating().Timeout(1).Build() s.ClusterSetslot().Slot(1).Migrating().Build() s.ClusterSetslot().Slot(1).Stable().NodeId("1").Build() + s.ClusterSetslot().Slot(1).Stable().Timeout(1).Build() s.ClusterSetslot().Slot(1).Stable().Build() s.ClusterSetslot().Slot(1).Node().NodeId("1").Build() + s.ClusterSetslot().Slot(1).Node().Timeout(1).Build() s.ClusterSetslot().Slot(1).Node().Build() s.ClusterShards().Build() s.ClusterSlaves().NodeId("1").Build() + s.ClusterSlotStats().Slotsrange().StartSlot(1).EndSlot(1).Build() + s.ClusterSlotStats().Orderby().Metric("1").Limit(1).Asc().Build() + s.ClusterSlotStats().Orderby().Metric("1").Limit(1).Desc().Build() + s.ClusterSlotStats().Orderby().Metric("1").Limit(1).Build() + s.ClusterSlotStats().Orderby().Metric("1").Asc().Build() + s.ClusterSlotStats().Orderby().Metric("1").Desc().Build() + s.ClusterSlotStats().Orderby().Metric("1").Build() s.ClusterSlots().Build() s.Readonly().Build() s.Readwrite().Build() diff --git a/internal/cmds/gen_connection.go b/internal/cmds/gen_connection.go index 15e33efd..ae769c8d 100644 --- a/internal/cmds/gen_connection.go +++ b/internal/cmds/gen_connection.go @@ -68,6 +68,31 @@ func (c ClientCachingModeYes) Build() Completed { return Completed{cs: c.cs, cf: uint16(c.cf), ks: c.ks} } +type ClientCapa Incomplete + +func (b Builder) ClientCapa() (c ClientCapa) { + c = ClientCapa{cs: get(), ks: b.ks} + c.cs.s = append(c.cs.s, "CLIENT", "CAPA") + return c +} + +func (c ClientCapa) Capability(capability ...string) ClientCapaCapability { + c.cs.s = append(c.cs.s, capability...) + return (ClientCapaCapability)(c) +} + +type ClientCapaCapability Incomplete + +func (c ClientCapaCapability) Capability(capability ...string) ClientCapaCapability { + c.cs.s = append(c.cs.s, capability...) + return c +} + +func (c ClientCapaCapability) Build() Completed { + c.cs.Build() + return Completed{cs: c.cs, cf: uint16(c.cf), ks: c.ks} +} + type ClientGetname Incomplete func (b Builder) ClientGetname() (c ClientGetname) { diff --git a/internal/cmds/gen_connection_test.go b/internal/cmds/gen_connection_test.go index 3d4dbb5b..3b380076 100644 --- a/internal/cmds/gen_connection_test.go +++ b/internal/cmds/gen_connection_test.go @@ -9,6 +9,7 @@ func connection0(s Builder) { s.Auth().Password("1").Build() s.ClientCaching().Yes().Build() s.ClientCaching().No().Build() + s.ClientCapa().Capability("1").Capability("1").Build() s.ClientGetname().Build() s.ClientGetredir().Build() s.ClientId().Build() @@ -104,10 +105,10 @@ func connection0(s Builder) { s.ClientPause().Timeout(1).Build() s.ClientReply().On().Build() s.ClientReply().Off().Build() - s.ClientReply().Skip().Build() } func connection1(s Builder) { + s.ClientReply().Skip().Build() s.ClientSetinfo().Libname("1").Build() s.ClientSetinfo().Libver("1").Build() s.ClientSetname().ConnectionName("1").Build() diff --git a/internal/cmds/gen_scripting.go b/internal/cmds/gen_scripting.go index 75eec025..49a33cc8 100644 --- a/internal/cmds/gen_scripting.go +++ b/internal/cmds/gen_scripting.go @@ -942,3 +942,23 @@ func (c ScriptLoadScript) Build() Completed { c.cs.Build() return Completed{cs: c.cs, cf: uint16(c.cf), ks: c.ks} } + +type ScriptShow Incomplete + +func (b Builder) ScriptShow() (c ScriptShow) { + c = ScriptShow{cs: get(), ks: b.ks} + c.cs.s = append(c.cs.s, "SCRIPT", "SHOW") + return c +} + +func (c ScriptShow) Sha1(sha1 string) ScriptShowSha1 { + c.cs.s = append(c.cs.s, sha1) + return (ScriptShowSha1)(c) +} + +type ScriptShowSha1 Incomplete + +func (c ScriptShowSha1) Build() Completed { + c.cs.Build() + return Completed{cs: c.cs, cf: uint16(c.cf), ks: c.ks} +} diff --git a/internal/cmds/gen_scripting_test.go b/internal/cmds/gen_scripting_test.go index b380718f..777f57f4 100644 --- a/internal/cmds/gen_scripting_test.go +++ b/internal/cmds/gen_scripting_test.go @@ -68,6 +68,7 @@ func scripting0(s Builder) { s.ScriptFlush().Build() s.ScriptKill().Build() s.ScriptLoad().Script("1").Build() + s.ScriptShow().Sha1("1").Build() } func TestCommand_InitSlot_scripting(t *testing.T) { diff --git a/internal/cmds/gen_sorted_set.go b/internal/cmds/gen_sorted_set.go index 7150575a..a48f4ad4 100644 --- a/internal/cmds/gen_sorted_set.go +++ b/internal/cmds/gen_sorted_set.go @@ -2197,6 +2197,11 @@ func (c Zscan) Key(key string) ZscanKey { type ZscanCount Incomplete +func (c ZscanCount) Noscores() ZscanNoscores { + c.cs.s = append(c.cs.s, "NOSCORES") + return (ZscanNoscores)(c) +} + func (c ZscanCount) Build() Completed { c.cs.Build() return Completed{cs: c.cs, cf: uint16(c.cf), ks: c.ks} @@ -2214,6 +2219,11 @@ func (c ZscanCursor) Count(count int64) ZscanCount { return (ZscanCount)(c) } +func (c ZscanCursor) Noscores() ZscanNoscores { + c.cs.s = append(c.cs.s, "NOSCORES") + return (ZscanNoscores)(c) +} + func (c ZscanCursor) Build() Completed { c.cs.Build() return Completed{cs: c.cs, cf: uint16(c.cf), ks: c.ks} @@ -2233,11 +2243,23 @@ func (c ZscanMatch) Count(count int64) ZscanCount { return (ZscanCount)(c) } +func (c ZscanMatch) Noscores() ZscanNoscores { + c.cs.s = append(c.cs.s, "NOSCORES") + return (ZscanNoscores)(c) +} + func (c ZscanMatch) Build() Completed { c.cs.Build() return Completed{cs: c.cs, cf: uint16(c.cf), ks: c.ks} } +type ZscanNoscores Incomplete + +func (c ZscanNoscores) Build() Completed { + c.cs.Build() + return Completed{cs: c.cs, cf: uint16(c.cf), ks: c.ks} +} + type Zscore Incomplete func (b Builder) Zscore() (c Zscore) { diff --git a/internal/cmds/gen_sorted_set_test.go b/internal/cmds/gen_sorted_set_test.go index 3a59ccb5..3e633a73 100644 --- a/internal/cmds/gen_sorted_set_test.go +++ b/internal/cmds/gen_sorted_set_test.go @@ -160,9 +160,12 @@ func sorted_set1(s Builder) { s.Zrevrank().Key("1").Member("1").Withscore().Cache() s.Zrevrank().Key("1").Member("1").Build() s.Zrevrank().Key("1").Member("1").Cache() + s.Zscan().Key("1").Cursor(1).Match("1").Count(1).Noscores().Build() s.Zscan().Key("1").Cursor(1).Match("1").Count(1).Build() + s.Zscan().Key("1").Cursor(1).Match("1").Noscores().Build() s.Zscan().Key("1").Cursor(1).Match("1").Build() s.Zscan().Key("1").Cursor(1).Count(1).Build() + s.Zscan().Key("1").Cursor(1).Noscores().Build() s.Zscan().Key("1").Cursor(1).Build() s.Zscore().Key("1").Member("1").Build() s.Zscore().Key("1").Member("1").Cache()