@@ -8802,7 +8802,7 @@ var _ = Describe("Commands", func() {
88028802 })
88038803 })
88048804
8805- Describe ("SlowLogGet " , func () {
8805+ Describe ("SlowLog " , func () {
88068806 It ("returns slow query result" , func () {
88078807 const key = "slowlog-log-slower-than"
88088808
@@ -8819,6 +8819,114 @@ var _ = Describe("Commands", func() {
88198819 Expect (err ).NotTo (HaveOccurred ())
88208820 Expect (len (result )).NotTo (BeZero ())
88218821 })
8822+
8823+ It ("returns the number of slow queries" , Label ("NonRedisEnterprise" ), func () {
8824+ // Reset slowlog
8825+ err := client .SlowLogReset (ctx ).Err ()
8826+ Expect (err ).NotTo (HaveOccurred ())
8827+
8828+ const key = "slowlog-log-slower-than"
8829+
8830+ old := client .ConfigGet (ctx , key ).Val ()
8831+ // first slowlog entry is the config set command itself
8832+ client .ConfigSet (ctx , key , "0" )
8833+ defer client .ConfigSet (ctx , key , old [key ])
8834+
8835+ // Set a key to trigger a slow query, and this is the second slowlog entry
8836+ client .Set (ctx , "test" , "true" , 0 )
8837+ result , err := client .SlowLogLen (ctx ).Result ()
8838+ Expect (err ).NotTo (HaveOccurred ())
8839+ Expect (result ).Should (Equal (int64 (2 )))
8840+
8841+ // Reset slowlog
8842+ err = client .SlowLogReset (ctx ).Err ()
8843+ Expect (err ).NotTo (HaveOccurred ())
8844+
8845+ // Check if slowlog is empty, this is the first slowlog entry after reset
8846+ result , err = client .SlowLogLen (ctx ).Result ()
8847+ Expect (err ).NotTo (HaveOccurred ())
8848+ Expect (result ).Should (Equal (int64 (1 )))
8849+ })
8850+ })
8851+
8852+ Describe ("Latency" , Label ("NonRedisEnterprise" ), func () {
8853+ It ("returns latencies" , func () {
8854+ const key = "latency-monitor-threshold"
8855+
8856+ old := client .ConfigGet (ctx , key ).Val ()
8857+ client .ConfigSet (ctx , key , "1" )
8858+ defer client .ConfigSet (ctx , key , old [key ])
8859+
8860+ err := client .Do (ctx , "DEBUG" , "SLEEP" , 0.01 ).Err ()
8861+ Expect (err ).NotTo (HaveOccurred ())
8862+
8863+ result , err := client .Latency (ctx ).Result ()
8864+ Expect (err ).NotTo (HaveOccurred ())
8865+ Expect (len (result )).NotTo (BeZero ())
8866+ })
8867+
8868+ It ("reset all latencies" , func () {
8869+ const key = "latency-monitor-threshold"
8870+
8871+ result , err := client .Latency (ctx ).Result ()
8872+ // reset all latencies
8873+ err = client .LatencyReset (ctx ).Err ()
8874+ Expect (err ).NotTo (HaveOccurred ())
8875+
8876+ old := client .ConfigGet (ctx , key ).Val ()
8877+ client .ConfigSet (ctx , key , "1" )
8878+ defer client .ConfigSet (ctx , key , old [key ])
8879+
8880+ // get latency after reset
8881+ result , err = client .Latency (ctx ).Result ()
8882+ Expect (err ).NotTo (HaveOccurred ())
8883+ Expect (len (result )).Should (Equal (0 ))
8884+
8885+ // create a new latency
8886+ err = client .Do (ctx , "DEBUG" , "SLEEP" , 0.01 ).Err ()
8887+ Expect (err ).NotTo (HaveOccurred ())
8888+
8889+ // get latency after create a new latency
8890+ result , err = client .Latency (ctx ).Result ()
8891+ Expect (err ).NotTo (HaveOccurred ())
8892+ Expect (len (result )).Should (Equal (1 ))
8893+
8894+ // reset all latencies again
8895+ err = client .LatencyReset (ctx ).Err ()
8896+ Expect (err ).NotTo (HaveOccurred ())
8897+
8898+ // get latency after reset again
8899+ result , err = client .Latency (ctx ).Result ()
8900+ Expect (err ).NotTo (HaveOccurred ())
8901+ Expect (len (result )).Should (Equal (0 ))
8902+ })
8903+
8904+ It ("reset latencies by add event name args" , func () {
8905+ const key = "latency-monitor-threshold"
8906+
8907+ old := client .ConfigGet (ctx , key ).Val ()
8908+ client .ConfigSet (ctx , key , "1" )
8909+ defer client .ConfigSet (ctx , key , old [key ])
8910+
8911+ result , err := client .Latency (ctx ).Result ()
8912+ Expect (err ).NotTo (HaveOccurred ())
8913+ Expect (len (result )).Should (Equal (0 ))
8914+
8915+ err = client .Do (ctx , "DEBUG" , "SLEEP" , 0.01 ).Err ()
8916+ Expect (err ).NotTo (HaveOccurred ())
8917+
8918+ result , err = client .Latency (ctx ).Result ()
8919+ Expect (err ).NotTo (HaveOccurred ())
8920+ Expect (len (result )).Should (Equal (1 ))
8921+
8922+ // reset latency by event name
8923+ err = client .LatencyReset (ctx , result [0 ].Name ).Err ()
8924+ Expect (err ).NotTo (HaveOccurred ())
8925+
8926+ result , err = client .Latency (ctx ).Result ()
8927+ Expect (err ).NotTo (HaveOccurred ())
8928+ Expect (len (result )).Should (Equal (0 ))
8929+ })
88228930 })
88238931})
88248932
0 commit comments