2020-07-26 17:09:05 +08:00
|
|
|
package redis
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
|
|
red "github.com/go-redis/redis"
|
2022-01-04 15:51:32 +08:00
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
|
|
|
"github.com/zeromicro/go-zero/core/mapping"
|
|
|
|
|
"github.com/zeromicro/go-zero/core/timex"
|
2020-07-26 17:09:05 +08:00
|
|
|
)
|
|
|
|
|
|
2021-11-01 08:20:35 +08:00
|
|
|
func checkDuration(proc func(red.Cmder) error) func(red.Cmder) error {
|
|
|
|
|
return func(cmd red.Cmder) error {
|
|
|
|
|
start := timex.Now()
|
2020-07-26 17:09:05 +08:00
|
|
|
|
2021-11-01 08:20:35 +08:00
|
|
|
defer func() {
|
|
|
|
|
duration := timex.Since(start)
|
|
|
|
|
if duration > slowThreshold.Load() {
|
|
|
|
|
var buf strings.Builder
|
|
|
|
|
for i, arg := range cmd.Args() {
|
|
|
|
|
if i > 0 {
|
|
|
|
|
buf.WriteByte(' ')
|
2020-07-26 17:09:05 +08:00
|
|
|
}
|
2021-11-01 08:20:35 +08:00
|
|
|
buf.WriteString(mapping.Repr(arg))
|
2020-07-26 17:09:05 +08:00
|
|
|
}
|
2021-11-01 08:20:35 +08:00
|
|
|
logx.WithDuration(duration).Slowf("[REDIS] slowcall on executing: %s", buf.String())
|
|
|
|
|
}
|
|
|
|
|
}()
|
2020-07-26 17:09:05 +08:00
|
|
|
|
2021-11-01 08:20:35 +08:00
|
|
|
return proc(cmd)
|
2020-07-26 17:09:05 +08:00
|
|
|
}
|
|
|
|
|
}
|