process.go 825 B

1234567891011121314151617181920212223242526272829303132333435
  1. package redis
  2. import (
  3. "strings"
  4. "time"
  5. red "github.com/go-redis/redis"
  6. "github.com/tal-tech/go-zero/core/logx"
  7. "github.com/tal-tech/go-zero/core/mapping"
  8. "github.com/tal-tech/go-zero/core/timex"
  9. )
  10. func checkDuration(slowThreshold time.Duration) func(proc func(red.Cmder) error) func(red.Cmder) error {
  11. return func(proc func(red.Cmder) error) func(red.Cmder) error {
  12. return func(cmd red.Cmder) error {
  13. start := timex.Now()
  14. defer func() {
  15. duration := timex.Since(start)
  16. if duration > slowThreshold {
  17. var buf strings.Builder
  18. for i, arg := range cmd.Args() {
  19. if i > 0 {
  20. buf.WriteByte(' ')
  21. }
  22. buf.WriteString(mapping.Repr(arg))
  23. }
  24. logx.WithDuration(duration).Slowf("[REDIS] slowcall on executing: %s", buf.String())
  25. }
  26. }()
  27. return proc(cmd)
  28. }
  29. }
  30. }