From 07656a01bf00af52fa2484908a4c97a5feb16125 Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Thu, 21 May 2020 09:24:19 +0300 Subject: [PATCH] Add redis.Error interface and export ErrClosed Fixes https://github.com/go-redis/redis/issues/1295 Closes https://github.com/go-redis/redis/pull/1296 --- error.go | 15 +++++++++++++++ internal/proto/reader.go | 2 ++ 2 files changed, 17 insertions(+) diff --git a/error.go b/error.go index a84c44f1..0ffaca9f 100644 --- a/error.go +++ b/error.go @@ -6,9 +6,24 @@ import ( "net" "strings" + "github.com/go-redis/redis/v7/internal/pool" "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 { switch err { case nil, context.Canceled, context.DeadlineExceeded: diff --git a/internal/proto/reader.go b/internal/proto/reader.go index 24fc0bd8..d3f646e9 100644 --- a/internal/proto/reader.go +++ b/internal/proto/reader.go @@ -24,6 +24,8 @@ type RedisError string func (e RedisError) Error() string { return string(e) } +func (RedisError) RedisError() {} + //------------------------------------------------------------------------------ type MultiBulkParse func(*Reader, int64) (interface{}, error)