Skip to content

Commit 07656a0

Browse files
committed
Add redis.Error interface and export ErrClosed
Fixes #1295 Closes #1296
1 parent 2960952 commit 07656a0

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

error.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,24 @@ import (
66
"net"
77
"strings"
88

9+
"github.com/go-redis/redis/v7/internal/pool"
910
"github.com/go-redis/redis/v7/internal/proto"
1011
)
1112

13+
var ErrClosed = pool.ErrClosed
14+
15+
type Error interface {
16+
error
17+
18+
// RedisError is a no-op function but
19+
// serves to distinguish types that are Redis
20+
// errors from ordinary errors: a type is a
21+
// Redis error if it has a RedisError method.
22+
RedisError()
23+
}
24+
25+
var _ Error = proto.RedisError("")
26+
1227
func isRetryableError(err error, retryTimeout bool) bool {
1328
switch err {
1429
case nil, context.Canceled, context.DeadlineExceeded:

internal/proto/reader.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ type RedisError string
2424

2525
func (e RedisError) Error() string { return string(e) }
2626

27+
func (RedisError) RedisError() {}
28+
2729
//------------------------------------------------------------------------------
2830

2931
type MultiBulkParse func(*Reader, int64) (interface{}, error)

0 commit comments

Comments
 (0)