forked from mirror/redis
Don't remove connection from the pool on redis errors.
This commit is contained in:
parent
5019689b0e
commit
deb41df992
|
@ -0,0 +1,23 @@
|
|||
package redis
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// Redis nil reply.
|
||||
var Nil = errorf("redis: nil")
|
||||
|
||||
// Redis transaction failed.
|
||||
var TxFailedErr = errorf("redis: transaction failed")
|
||||
|
||||
type redisError struct {
|
||||
s string
|
||||
}
|
||||
|
||||
func errorf(s string, args ...interface{}) redisError {
|
||||
return redisError{s: fmt.Sprintf(s, args...)}
|
||||
}
|
||||
|
||||
func (err redisError) Error() string {
|
||||
return err.s
|
||||
}
|
|
@ -10,12 +10,6 @@ import (
|
|||
|
||||
type multiBulkParser func(rd reader, n int64) (interface{}, error)
|
||||
|
||||
// Redis nil reply.
|
||||
var Nil = errors.New("redis: nil")
|
||||
|
||||
// Redis transaction failed.
|
||||
var TxFailedErr = errors.New("redis: transaction failed")
|
||||
|
||||
var (
|
||||
errReaderTooSmall = errors.New("redis: reader is too small")
|
||||
errInvalidReplyType = errors.New("redis: invalid reply type")
|
||||
|
@ -132,7 +126,7 @@ func parseReply(rd reader, p multiBulkParser) (interface{}, error) {
|
|||
|
||||
switch line[0] {
|
||||
case '-':
|
||||
return nil, errors.New(string(line[1:]))
|
||||
return nil, errorf(string(line[1:]))
|
||||
case '+':
|
||||
return string(line[1:]), nil
|
||||
case ':':
|
||||
|
|
12
redis.go
12
redis.go
|
@ -65,12 +65,14 @@ func (c *baseClient) init(cn *conn, password string, db int64) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (c *baseClient) freeConn(cn *conn, err error) {
|
||||
if err == Nil || err == TxFailedErr {
|
||||
c.putConn(cn)
|
||||
} else {
|
||||
c.removeConn(cn)
|
||||
func (c *baseClient) freeConn(cn *conn, ei error) error {
|
||||
if cn.rd.Buffered() > 0 {
|
||||
return c.connPool.Remove(cn)
|
||||
}
|
||||
if _, ok := ei.(redisError); ok {
|
||||
return c.connPool.Put(cn)
|
||||
}
|
||||
return c.connPool.Remove(cn)
|
||||
}
|
||||
|
||||
func (c *baseClient) removeConn(cn *conn) {
|
||||
|
|
Loading…
Reference in New Issue