feat: slow threshold customizable in redis (#1185)

* feat: slow threshold customizable in redis

* chore: improve config robustness
This commit is contained in:
Kevin Wan
2021-10-31 22:14:20 +08:00
committed by GitHub
parent b4d1c6da2c
commit 429f85a9de
8 changed files with 83 additions and 33 deletions

View File

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