Skip to content

Commit c176672

Browse files
destinyoooondyakov
andauthored
feat: Add support for certain slowlog commands (#3585)
* Add support for certain slowlog commands * add NonRedisEnterprise label for slow reset test --------- Co-authored-by: Nedyalko Dyakov <[email protected]>
1 parent 63fbaaf commit c176672

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

commands.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,8 @@ type Cmdable interface {
211211
ShutdownNoSave(ctx context.Context) *StatusCmd
212212
SlaveOf(ctx context.Context, host, port string) *StatusCmd
213213
SlowLogGet(ctx context.Context, num int64) *SlowLogCmd
214+
SlowLogLen(ctx context.Context) *IntCmd
215+
SlowLogReset(ctx context.Context) *StatusCmd
214216
Time(ctx context.Context) *TimeCmd
215217
DebugObject(ctx context.Context, key string) *StringCmd
216218
MemoryUsage(ctx context.Context, key string, samples ...int) *IntCmd
@@ -675,6 +677,18 @@ func (c cmdable) SlowLogGet(ctx context.Context, num int64) *SlowLogCmd {
675677
return cmd
676678
}
677679

680+
func (c cmdable) SlowLogLen(ctx context.Context) *IntCmd {
681+
cmd := NewIntCmd(ctx, "slowlog", "len")
682+
_ = c(ctx, cmd)
683+
return cmd
684+
}
685+
686+
func (c cmdable) SlowLogReset(ctx context.Context) *StatusCmd {
687+
cmd := NewStatusCmd(ctx, "slowlog", "reset")
688+
_ = c(ctx, cmd)
689+
return cmd
690+
}
691+
678692
func (c cmdable) Latency(ctx context.Context) *LatencyCmd {
679693
cmd := NewLatencyCmd(ctx, "latency", "latest")
680694
_ = c(ctx, cmd)

commands_test.go

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8294,7 +8294,7 @@ var _ = Describe("Commands", func() {
82948294
})
82958295
})
82968296

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

@@ -8311,6 +8311,34 @@ var _ = Describe("Commands", func() {
83118311
Expect(err).NotTo(HaveOccurred())
83128312
Expect(len(result)).NotTo(BeZero())
83138313
})
8314+
8315+
It("returns the number of slow queries", Label("NonRedisEnterprise"), func() {
8316+
// Reset slowlog
8317+
err := client.SlowLogReset(ctx).Err()
8318+
Expect(err).NotTo(HaveOccurred())
8319+
8320+
const key = "slowlog-log-slower-than"
8321+
8322+
old := client.ConfigGet(ctx, key).Val()
8323+
// first slowlog entry is the config set command itself
8324+
client.ConfigSet(ctx, key, "0")
8325+
defer client.ConfigSet(ctx, key, old[key])
8326+
8327+
// Set a key to trigger a slow query, and this is the second slowlog entry
8328+
client.Set(ctx, "test", "true", 0)
8329+
result, err := client.SlowLogLen(ctx).Result()
8330+
Expect(err).NotTo(HaveOccurred())
8331+
Expect(result).Should(Equal(int64(2)))
8332+
8333+
// Reset slowlog
8334+
err = client.SlowLogReset(ctx).Err()
8335+
Expect(err).NotTo(HaveOccurred())
8336+
8337+
// Check if slowlog is empty, this is the first slowlog entry after reset
8338+
result, err = client.SlowLogLen(ctx).Result()
8339+
Expect(err).NotTo(HaveOccurred())
8340+
Expect(result).Should(Equal(int64(1)))
8341+
})
83148342
})
83158343

83168344
Describe("Latency", Label("NonRedisEnterprise"), func() {

0 commit comments

Comments
 (0)