From 1f78eea75ebde5d49bf950f1b05f0144ee0042f2 Mon Sep 17 00:00:00 2001 From: destinyoooo <643604012@qq.com> Date: Wed, 5 Nov 2025 21:47:33 +0800 Subject: [PATCH 1/2] Add support for certain slowlog commands --- commands.go | 14 ++++++++++++++ commands_test.go | 30 +++++++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/commands.go b/commands.go index f313728d8..c7afb2a9e 100644 --- a/commands.go +++ b/commands.go @@ -211,6 +211,8 @@ type Cmdable interface { ShutdownNoSave(ctx context.Context) *StatusCmd SlaveOf(ctx context.Context, host, port string) *StatusCmd SlowLogGet(ctx context.Context, num int64) *SlowLogCmd + SlowLogLen(ctx context.Context) *IntCmd + SlowLogReset(ctx context.Context) *StatusCmd Time(ctx context.Context) *TimeCmd DebugObject(ctx context.Context, key string) *StringCmd MemoryUsage(ctx context.Context, key string, samples ...int) *IntCmd @@ -673,6 +675,18 @@ func (c cmdable) SlowLogGet(ctx context.Context, num int64) *SlowLogCmd { return cmd } +func (c cmdable) SlowLogLen(ctx context.Context) *IntCmd { + cmd := NewIntCmd(ctx, "slowlog", "len") + _ = c(ctx, cmd) + return cmd +} + +func (c cmdable) SlowLogReset(ctx context.Context) *StatusCmd { + cmd := NewStatusCmd(ctx, "slowlog", "reset") + _ = c(ctx, cmd) + return cmd +} + func (c cmdable) Sync(_ context.Context) { panic("not implemented") } diff --git a/commands_test.go b/commands_test.go index f528b5cee..96ee5c3a8 100644 --- a/commands_test.go +++ b/commands_test.go @@ -8163,7 +8163,7 @@ var _ = Describe("Commands", func() { }) }) - Describe("SlowLogGet", func() { + Describe("SlowLog", func() { It("returns slow query result", func() { const key = "slowlog-log-slower-than" @@ -8180,6 +8180,34 @@ var _ = Describe("Commands", func() { Expect(err).NotTo(HaveOccurred()) Expect(len(result)).NotTo(BeZero()) }) + + It("returns the number of slow queries", func() { + // Reset slowlog + err := client.SlowLogReset(ctx).Err() + Expect(err).NotTo(HaveOccurred()) + + const key = "slowlog-log-slower-than" + + old := client.ConfigGet(ctx, key).Val() + // first slowlog entry is the config set command itself + client.ConfigSet(ctx, key, "0") + defer client.ConfigSet(ctx, key, old[key]) + + // Set a key to trigger a slow query, and this is the second slowlog entry + client.Set(ctx, "test", "true", 0) + result, err := client.SlowLogLen(ctx).Result() + Expect(err).NotTo(HaveOccurred()) + Expect(result).Should(Equal(int64(2))) + + // Reset slowlog + err = client.SlowLogReset(ctx).Err() + Expect(err).NotTo(HaveOccurred()) + + // Check if slowlog is empty, this is the first slowlog entry after reset + result, err = client.SlowLogLen(ctx).Result() + Expect(err).NotTo(HaveOccurred()) + Expect(result).Should(Equal(int64(1))) + }) }) }) From 0dac55ade1c2834c86adba425b26f8a39a68004c Mon Sep 17 00:00:00 2001 From: destinyoooo <643604012@qq.com> Date: Wed, 5 Nov 2025 22:44:59 +0800 Subject: [PATCH 2/2] add NonRedisEnterprise label for slow reset test --- commands_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands_test.go b/commands_test.go index 96ee5c3a8..d8e4decb4 100644 --- a/commands_test.go +++ b/commands_test.go @@ -8181,7 +8181,7 @@ var _ = Describe("Commands", func() { Expect(len(result)).NotTo(BeZero()) }) - It("returns the number of slow queries", func() { + It("returns the number of slow queries", Label("NonRedisEnterprise"), func() { // Reset slowlog err := client.SlowLogReset(ctx).Err() Expect(err).NotTo(HaveOccurred())