Merge pull request #394 from go-redis/fix/rm-errors-pack

Remove internal errors package that clashes with std lib.
This commit is contained in:
Vladimir Mihailenco 2016-10-09 14:50:36 +03:00 committed by GitHub
commit cb3f27133f
9 changed files with 34 additions and 41 deletions

View File

@ -7,12 +7,11 @@ import (
"time"
"gopkg.in/redis.v5/internal"
"gopkg.in/redis.v5/internal/errors"
"gopkg.in/redis.v5/internal/hashtag"
"gopkg.in/redis.v5/internal/pool"
)
var errClusterNoNodes = errors.RedisError("redis: cluster has no nodes")
var errClusterNoNodes = internal.RedisError("redis: cluster has no nodes")
// ClusterOptions are used to configure a cluster client and should be
// passed to NewClusterClient.
@ -382,20 +381,20 @@ func (c *ClusterClient) Process(cmd Cmder) error {
}
// If slave is loading - read from master.
if c.opt.ReadOnly && errors.IsLoading(err) {
if c.opt.ReadOnly && internal.IsLoadingError(err) {
node.loading = time.Now()
continue
}
// On network errors try random node.
if errors.IsRetryable(err) {
if internal.IsRetryableError(err) {
node, err = c.randomNode()
continue
}
var moved bool
var addr string
moved, ask, addr = errors.IsMoved(err)
moved, ask, addr = internal.IsMovedError(err)
if moved || ask {
if slot >= 0 {
master, _ := c.slotMasterNode(slot)
@ -650,11 +649,11 @@ func (c *ClusterClient) execClusterCmds(
if err == nil {
continue
}
if errors.IsNetwork(err) {
if internal.IsNetworkError(err) {
cmd.reset()
failedCmds[nil] = append(failedCmds[nil], cmds[i:]...)
break
} else if moved, ask, addr := errors.IsMoved(err); moved {
} else if moved, ask, addr := internal.IsMovedError(err); moved {
c.lazyReloadSlots()
cmd.reset()
node, err := c.nodeByAddr(addr)

View File

@ -6,7 +6,6 @@ import (
"time"
"gopkg.in/redis.v5/internal"
"gopkg.in/redis.v5/internal/errors"
)
func readTimeout(timeout time.Duration) time.Duration {
@ -1710,7 +1709,7 @@ func (c *cmdable) shutdown(modifier string) *StatusCmd {
}
} else {
// Server did not quit. String reply contains the reason.
cmd.err = errors.RedisError(cmd.val)
cmd.err = internal.RedisError(cmd.val)
cmd.val = ""
}
return cmd

View File

@ -1,4 +1,4 @@
package errors
package internal
import (
"io"
@ -12,16 +12,16 @@ type RedisError string
func (e RedisError) Error() string { return string(e) }
func IsRetryable(err error) bool {
return IsNetwork(err)
func IsRetryableError(err error) bool {
return IsNetworkError(err)
}
func IsInternal(err error) bool {
func IsInternalError(err error) bool {
_, ok := err.(RedisError)
return ok
}
func IsNetwork(err error) bool {
func IsNetworkError(err error) bool {
if err == io.EOF {
return true
}
@ -33,7 +33,7 @@ func IsBadConn(err error, allowTimeout bool) bool {
if err == nil {
return false
}
if IsInternal(err) {
if IsInternalError(err) {
return false
}
if allowTimeout {
@ -44,8 +44,8 @@ func IsBadConn(err error, allowTimeout bool) bool {
return true
}
func IsMoved(err error) (moved bool, ask bool, addr string) {
if !IsInternal(err) {
func IsMovedError(err error) (moved bool, ask bool, addr string) {
if !IsInternalError(err) {
return
}
@ -66,6 +66,6 @@ func IsMoved(err error) (moved bool, ask bool, addr string) {
return
}
func IsLoading(err error) bool {
func IsLoadingError(err error) bool {
return strings.HasPrefix(err.Error(), "LOADING")
}

View File

@ -5,7 +5,7 @@ import (
"fmt"
"strconv"
"gopkg.in/redis.v5/internal/errors"
"gopkg.in/redis.v5/internal"
)
const (
@ -18,7 +18,7 @@ const (
const defaultBufSize = 4096
var errScanNil = errors.RedisError("redis: Scan(nil)")
const errScanNil = internal.RedisError("redis: Scan(nil)")
func Scan(b []byte, val interface{}) error {
switch v := val.(type) {

View File

@ -2,17 +2,16 @@ package proto
import (
"bufio"
"errors"
"fmt"
"io"
"strconv"
ierrors "gopkg.in/redis.v5/internal/errors"
"gopkg.in/redis.v5/internal"
)
type MultiBulkParse func(*Reader, int64) (interface{}, error)
const errEmptyReply = internal.RedisError("redis: reply is empty")
var errEmptyReply = errors.New("redis: reply is empty")
type MultiBulkParse func(*Reader, int64) (interface{}, error)
type Reader struct {
src *bufio.Reader
@ -59,7 +58,7 @@ func (p *Reader) ReadLine() ([]byte, error) {
return nil, errEmptyReply
}
if isNilReply(line) {
return nil, ierrors.Nil
return nil, internal.Nil
}
return line, nil
}
@ -209,7 +208,7 @@ func (p *Reader) ReadScanReply() ([]string, uint64, error) {
func (p *Reader) parseBytesValue(line []byte) ([]byte, error) {
if isNilReply(line) {
return nil, ierrors.Nil
return nil, internal.Nil
}
replyLen, err := strconv.Atoi(string(line[1:]))
@ -245,7 +244,7 @@ func isNilReply(b []byte) bool {
}
func parseErrorValue(line []byte) error {
return ierrors.RedisError(string(line[1:]))
return internal.RedisError(string(line[1:]))
}
func parseStatusValue(line []byte) ([]byte, error) {
@ -258,7 +257,7 @@ func parseIntValue(line []byte) (int64, error) {
func parseArrayLen(line []byte) (int64, error) {
if isNilReply(line) {
return 0, ierrors.Nil
return 0, internal.Nil
}
return parseIntValue(line)
}

View File

@ -4,7 +4,7 @@ import (
"sync"
"sync/atomic"
"gopkg.in/redis.v5/internal/errors"
"gopkg.in/redis.v5/internal"
"gopkg.in/redis.v5/internal/pool"
)
@ -100,7 +100,7 @@ func execCmds(cn *pool.Conn, cmds []Cmder) ([]Cmder, error) {
if firstCmdErr == nil {
firstCmdErr = err
}
if errors.IsRetryable(err) {
if internal.IsRetryableError(err) {
failedCmds = append(failedCmds, cmd)
}
}

View File

@ -6,7 +6,6 @@ import (
"time"
"gopkg.in/redis.v5/internal"
"gopkg.in/redis.v5/internal/errors"
"gopkg.in/redis.v5/internal/pool"
)
@ -212,7 +211,7 @@ func (c *PubSub) receiveMessage(timeout time.Duration) (*Message, error) {
for {
msgi, err := c.ReceiveTimeout(timeout)
if err != nil {
if !errors.IsNetwork(err) {
if !internal.IsNetworkError(err) {
return nil, err
}

View File

@ -5,12 +5,11 @@ import (
"log"
"gopkg.in/redis.v5/internal"
"gopkg.in/redis.v5/internal/errors"
"gopkg.in/redis.v5/internal/pool"
)
// Redis nil reply, .e.g. when key does not exist.
const Nil = errors.Nil
const Nil = internal.Nil
func SetLogger(logger *log.Logger) {
internal.Logger = logger
@ -42,7 +41,7 @@ func (c *baseClient) conn() (*pool.Conn, bool, error) {
}
func (c *baseClient) putConn(cn *pool.Conn, err error, allowTimeout bool) bool {
if errors.IsBadConn(err, allowTimeout) {
if internal.IsBadConn(err, allowTimeout) {
_ = c.connPool.Remove(cn, err)
return false
}
@ -101,7 +100,7 @@ func (c *baseClient) Process(cmd Cmder) error {
if err := writeCmd(cn, cmd); err != nil {
c.putConn(cn, err, false)
cmd.setErr(err)
if err != nil && errors.IsRetryable(err) {
if err != nil && internal.IsRetryableError(err) {
continue
}
return err
@ -109,7 +108,7 @@ func (c *baseClient) Process(cmd Cmder) error {
err = cmd.readReply(cn)
c.putConn(cn, err, readTimeout != nil)
if err != nil && errors.IsRetryable(err) {
if err != nil && internal.IsRetryableError(err) {
continue
}

6
tx.go
View File

@ -1,19 +1,17 @@
package redis
import (
"errors"
"fmt"
"gopkg.in/redis.v5/internal"
ierrors "gopkg.in/redis.v5/internal/errors"
"gopkg.in/redis.v5/internal/pool"
"gopkg.in/redis.v5/internal/proto"
)
// Redis transaction failed.
const TxFailedErr = ierrors.RedisError("redis: transaction failed")
const TxFailedErr = internal.RedisError("redis: transaction failed")
var errDiscard = errors.New("redis: Discard can be used only inside Exec")
var errDiscard = internal.RedisError("redis: Discard can be used only inside Exec")
// Tx implements Redis transactions as described in
// http://redis.io/topics/transactions. It's NOT safe for concurrent use