feat: slow threshold customizable in redis (#1187)

This commit is contained in:
Kevin Wan
2021-11-01 08:20:35 +08:00
committed by GitHub
parent 8be0f77d96
commit f13e6f1149
6 changed files with 48 additions and 54 deletions

View File

@@ -2,7 +2,6 @@ package redis
import (
"strings"
"time"
red "github.com/go-redis/redis"
"github.com/tal-tech/go-zero/core/logx"
@@ -10,26 +9,24 @@ import (
"github.com/tal-tech/go-zero/core/timex"
)
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()
func checkDuration(proc func(red.Cmder) error) func(red.Cmder) error {
return func(cmd red.Cmder) error {
start := timex.Now()
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))
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(' ')
}
logx.WithDuration(duration).Slowf("[REDIS] slowcall on executing: %s", buf.String())
buf.WriteString(mapping.Repr(arg))
}
}()
logx.WithDuration(duration).Slowf("[REDIS] slowcall on executing: %s", buf.String())
}
}()
return proc(cmd)
}
return proc(cmd)
}
}