|
@@ -1,7 +1,6 @@
|
|
|
package redis
|
|
|
|
|
|
import (
|
|
|
- "errors"
|
|
|
"git.aionnect.com/aionnect/go-common/utils/logger"
|
|
|
redisc "github.com/chasex/redis-go-cluster"
|
|
|
"github.com/gomodule/redigo/redis"
|
|
@@ -145,25 +144,35 @@ func (h *Hub) Do(cmd string, args ...interface{}) (interface{}, error) {
|
|
|
|
|
|
if nil != h.cluster {
|
|
|
return h.cluster.Do(cmd, args...)
|
|
|
- } else if h.pool != nil {
|
|
|
+ } else if nil != h.pool {
|
|
|
conn := h.pool.Get()
|
|
|
defer func(conn redis.Conn) {
|
|
|
_ = conn.Close()
|
|
|
}(conn)
|
|
|
do, err := conn.Do(cmd, args...)
|
|
|
- if err != nil {
|
|
|
+ if nil != err {
|
|
|
return nil, err
|
|
|
}
|
|
|
return do, nil
|
|
|
} else {
|
|
|
- return nil, errors.New("redis conn nil")
|
|
|
+ return nil, ErrRedisConnNil
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+const (
|
|
|
+ ErrRedisConnNil = ErrRedis("redis conn nil")
|
|
|
+)
|
|
|
+
|
|
|
+type ErrRedis string
|
|
|
+
|
|
|
+func (err ErrRedis) Error() string {
|
|
|
+ return string(err)
|
|
|
+}
|
|
|
+
|
|
|
func (h *Hub) Get() (redis.Conn, error) {
|
|
|
- if h.pool == nil {
|
|
|
+ if nil == h.pool {
|
|
|
err := h.conn()
|
|
|
- if err != nil {
|
|
|
+ if nil != err {
|
|
|
return nil, err
|
|
|
}
|
|
|
}
|