You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
go-zero/core/stores/redis/process.go

36 lines
825 B
Go

4 years ago
package redis
import (
"strings"
"time"
4 years ago
red "github.com/go-redis/redis"
"github.com/tal-tech/go-zero/core/logx"
"github.com/tal-tech/go-zero/core/mapping"
"github.com/tal-tech/go-zero/core/timex"
4 years ago
)
func checkDuration(slowThreshold time.Duration) func(proc func(red.Cmder) error) func(red.Cmder) error {
return func(proc func(red.Cmder) error) func(red.Cmder) error {
return func(cmd red.Cmder) error {
start := timex.Now()
4 years ago
defer func() {
duration := timex.Since(start)
if duration > slowThreshold {
var buf strings.Builder
for i, arg := range cmd.Args() {
if i > 0 {
buf.WriteByte(' ')
}
buf.WriteString(mapping.Repr(arg))
4 years ago
}
logx.WithDuration(duration).Slowf("[REDIS] slowcall on executing: %s", buf.String())
4 years ago
}
}()
4 years ago
return proc(cmd)
}
4 years ago
}
}