|
|
@ -2,10 +2,13 @@ package redis
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"io"
|
|
|
|
|
|
|
|
"net"
|
|
|
|
"strings"
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
|
|
red "github.com/go-redis/redis/v8"
|
|
|
|
red "github.com/go-redis/redis/v8"
|
|
|
|
|
|
|
|
"github.com/zeromicro/go-zero/core/breaker"
|
|
|
|
"github.com/zeromicro/go-zero/core/errorx"
|
|
|
|
"github.com/zeromicro/go-zero/core/errorx"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
|
|
"github.com/zeromicro/go-zero/core/mapping"
|
|
|
|
"github.com/zeromicro/go-zero/core/mapping"
|
|
|
@ -116,24 +119,17 @@ func formatError(err error) string {
|
|
|
|
return ""
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
es := err.Error()
|
|
|
|
opErr, ok := err.(*net.OpError)
|
|
|
|
switch {
|
|
|
|
if ok && opErr.Timeout() {
|
|
|
|
case strings.HasPrefix(es, "read"):
|
|
|
|
return "timeout"
|
|
|
|
return "read timeout"
|
|
|
|
|
|
|
|
case strings.HasPrefix(es, "dial"):
|
|
|
|
|
|
|
|
if strings.Contains(es, "connection refused") {
|
|
|
|
|
|
|
|
return "connection refused"
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "dial timeout"
|
|
|
|
|
|
|
|
case strings.HasPrefix(es, "write"):
|
|
|
|
switch err {
|
|
|
|
return "write timeout"
|
|
|
|
case io.EOF:
|
|
|
|
case strings.Contains(es, "EOF"):
|
|
|
|
|
|
|
|
return "eof"
|
|
|
|
return "eof"
|
|
|
|
case strings.Contains(es, "reset"):
|
|
|
|
case context.DeadlineExceeded:
|
|
|
|
return "reset"
|
|
|
|
return "context deadline"
|
|
|
|
case strings.Contains(es, "broken"):
|
|
|
|
case breaker.ErrServiceUnavailable:
|
|
|
|
return "broken pipe"
|
|
|
|
|
|
|
|
case strings.Contains(es, "breaker"):
|
|
|
|
|
|
|
|
return "breaker"
|
|
|
|
return "breaker"
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
return "unexpected error"
|
|
|
|
return "unexpected error"
|
|
|
|