@@ -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,114 @@ 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+ })
8342+ })
8343+
8344+ Describe ("Latency" , Label ("NonRedisEnterprise" ), func () {
8345+ It ("returns latencies" , func () {
8346+ const key = "latency-monitor-threshold"
8347+
8348+ old := client .ConfigGet (ctx , key ).Val ()
8349+ client .ConfigSet (ctx , key , "1" )
8350+ defer client .ConfigSet (ctx , key , old [key ])
8351+
8352+ err := client .Do (ctx , "DEBUG" , "SLEEP" , 0.01 ).Err ()
8353+ Expect (err ).NotTo (HaveOccurred ())
8354+
8355+ result , err := client .Latency (ctx ).Result ()
8356+ Expect (err ).NotTo (HaveOccurred ())
8357+ Expect (len (result )).NotTo (BeZero ())
8358+ })
8359+
8360+ It ("reset all latencies" , func () {
8361+ const key = "latency-monitor-threshold"
8362+
8363+ result , err := client .Latency (ctx ).Result ()
8364+ // reset all latencies
8365+ err = client .LatencyReset (ctx ).Err ()
8366+ Expect (err ).NotTo (HaveOccurred ())
8367+
8368+ old := client .ConfigGet (ctx , key ).Val ()
8369+ client .ConfigSet (ctx , key , "1" )
8370+ defer client .ConfigSet (ctx , key , old [key ])
8371+
8372+ // get latency after reset
8373+ result , err = client .Latency (ctx ).Result ()
8374+ Expect (err ).NotTo (HaveOccurred ())
8375+ Expect (len (result )).Should (Equal (0 ))
8376+
8377+ // create a new latency
8378+ err = client .Do (ctx , "DEBUG" , "SLEEP" , 0.01 ).Err ()
8379+ Expect (err ).NotTo (HaveOccurred ())
8380+
8381+ // get latency after create a new latency
8382+ result , err = client .Latency (ctx ).Result ()
8383+ Expect (err ).NotTo (HaveOccurred ())
8384+ Expect (len (result )).Should (Equal (1 ))
8385+
8386+ // reset all latencies again
8387+ err = client .LatencyReset (ctx ).Err ()
8388+ Expect (err ).NotTo (HaveOccurred ())
8389+
8390+ // get latency after reset again
8391+ result , err = client .Latency (ctx ).Result ()
8392+ Expect (err ).NotTo (HaveOccurred ())
8393+ Expect (len (result )).Should (Equal (0 ))
8394+ })
8395+
8396+ It ("reset latencies by add event name args" , func () {
8397+ const key = "latency-monitor-threshold"
8398+
8399+ old := client .ConfigGet (ctx , key ).Val ()
8400+ client .ConfigSet (ctx , key , "1" )
8401+ defer client .ConfigSet (ctx , key , old [key ])
8402+
8403+ result , err := client .Latency (ctx ).Result ()
8404+ Expect (err ).NotTo (HaveOccurred ())
8405+ Expect (len (result )).Should (Equal (0 ))
8406+
8407+ err = client .Do (ctx , "DEBUG" , "SLEEP" , 0.01 ).Err ()
8408+ Expect (err ).NotTo (HaveOccurred ())
8409+
8410+ result , err = client .Latency (ctx ).Result ()
8411+ Expect (err ).NotTo (HaveOccurred ())
8412+ Expect (len (result )).Should (Equal (1 ))
8413+
8414+ // reset latency by event name
8415+ err = client .LatencyReset (ctx , result [0 ].Name ).Err ()
8416+ Expect (err ).NotTo (HaveOccurred ())
8417+
8418+ result , err = client .Latency (ctx ).Result ()
8419+ Expect (err ).NotTo (HaveOccurred ())
8420+ Expect (len (result )).Should (Equal (0 ))
8421+ })
83148422 })
83158423})
83168424
0 commit comments