Merge pull request from go-redis/feature/redis-error

Add redis.Error interface and export ErrClosed
This commit is contained in:
Vladimir Mihailenco 2020-05-21 09:38:36 +03:00 committed by GitHub
commit 6e98832781
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 0 deletions
error.go
internal/proto

View File

@ -6,9 +6,24 @@ import (
"net" "net"
"strings" "strings"
"github.com/go-redis/redis/v7/internal/pool"
"github.com/go-redis/redis/v7/internal/proto" "github.com/go-redis/redis/v7/internal/proto"
) )
var ErrClosed = pool.ErrClosed
type Error interface {
error
// RedisError is a no-op function but
// serves to distinguish types that are Redis
// errors from ordinary errors: a type is a
// Redis error if it has a RedisError method.
RedisError()
}
var _ Error = proto.RedisError("")
func isRetryableError(err error, retryTimeout bool) bool { func isRetryableError(err error, retryTimeout bool) bool {
switch err { switch err {
case nil, context.Canceled, context.DeadlineExceeded: case nil, context.Canceled, context.DeadlineExceeded:

View File

@ -24,6 +24,8 @@ type RedisError string
func (e RedisError) Error() string { return string(e) } func (e RedisError) Error() string { return string(e) }
func (RedisError) RedisError() {}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
type MultiBulkParse func(*Reader, int64) (interface{}, error) type MultiBulkParse func(*Reader, int64) (interface{}, error)