process.go 683 B

1234567891011121314151617181920212223242526272829303132
  1. package redis
  2. import (
  3. "strings"
  4. "git.i2edu.net/i2/go-zero/core/logx"
  5. "git.i2edu.net/i2/go-zero/core/mapping"
  6. "git.i2edu.net/i2/go-zero/core/timex"
  7. red "github.com/go-redis/redis"
  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. }