Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -675,6 +677,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) Latency(ctx context.Context) *LatencyCmd {
cmd := NewLatencyCmd(ctx, "latency", "latest")
_ = c(ctx, cmd)
Expand Down
30 changes: 29 additions & 1 deletion commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8294,7 +8294,7 @@ var _ = Describe("Commands", func() {
})
})

Describe("SlowLogGet", func() {
Describe("SlowLog", func() {
It("returns slow query result", func() {
const key = "slowlog-log-slower-than"

Expand All @@ -8311,6 +8311,34 @@ var _ = Describe("Commands", func() {
Expect(err).NotTo(HaveOccurred())
Expect(len(result)).NotTo(BeZero())
})

It("returns the number of slow queries", Label("NonRedisEnterprise"), 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)))
})
})

Describe("Latency", Label("NonRedisEnterprise"), func() {
Expand Down
Loading