|
|
@ -2,6 +2,7 @@ package redis
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"errors"
|
|
|
|
"io"
|
|
|
|
"io"
|
|
|
|
"net"
|
|
|
|
"net"
|
|
|
|
"strings"
|
|
|
|
"strings"
|
|
|
@ -29,7 +30,6 @@ var (
|
|
|
|
type hook struct{}
|
|
|
|
type hook struct{}
|
|
|
|
|
|
|
|
|
|
|
|
func (h hook) DialHook(next red.DialHook) red.DialHook {
|
|
|
|
func (h hook) DialHook(next red.DialHook) red.DialHook {
|
|
|
|
// no need to implement
|
|
|
|
|
|
|
|
return next
|
|
|
|
return next
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -84,22 +84,23 @@ func (h hook) ProcessPipelineHook(next red.ProcessPipelineHook) red.ProcessPipel
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func formatError(err error) string {
|
|
|
|
func formatError(err error) string {
|
|
|
|
if err == nil || err == red.Nil {
|
|
|
|
if err == nil || errors.Is(err, red.Nil) {
|
|
|
|
return ""
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
opErr, ok := err.(*net.OpError)
|
|
|
|
var opErr *net.OpError
|
|
|
|
|
|
|
|
ok := errors.As(err, &opErr)
|
|
|
|
if ok && opErr.Timeout() {
|
|
|
|
if ok && opErr.Timeout() {
|
|
|
|
return "timeout"
|
|
|
|
return "timeout"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
switch err {
|
|
|
|
switch {
|
|
|
|
case io.EOF:
|
|
|
|
case err == io.EOF:
|
|
|
|
return "eof"
|
|
|
|
return "eof"
|
|
|
|
case context.DeadlineExceeded:
|
|
|
|
case errors.Is(err, context.DeadlineExceeded):
|
|
|
|
return "context deadline"
|
|
|
|
return "context deadline"
|
|
|
|
case breaker.ErrServiceUnavailable:
|
|
|
|
case errors.Is(err, breaker.ErrServiceUnavailable):
|
|
|
|
return "breaker"
|
|
|
|
return "breaker open"
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
return "unexpected error"
|
|
|
|
return "unexpected error"
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -140,7 +141,7 @@ func (h hook) startSpan(ctx context.Context, cmds ...red.Cmder) (context.Context
|
|
|
|
return ctx, func(err error) {
|
|
|
|
return ctx, func(err error) {
|
|
|
|
defer span.End()
|
|
|
|
defer span.End()
|
|
|
|
|
|
|
|
|
|
|
|
if err == nil || err == red.Nil {
|
|
|
|
if err == nil || errors.Is(err, red.Nil) {
|
|
|
|
span.SetStatus(codes.Ok, "")
|
|
|
|
span.SetStatus(codes.Ok, "")
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|