feat: slow threshold customizable in redis (#1185)
* feat: slow threshold customizable in redis * chore: improve config robustness
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user