process.go 692 B

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