|
@@ -96,12 +96,25 @@ func (h *Hub) conn() error {
|
|
|
pool, _ = h.createPool(host, dialOpts...)
|
|
|
h.pool = pool
|
|
|
}
|
|
|
- return nil
|
|
|
+ return h.ping()
|
|
|
}
|
|
|
|
|
|
// 连接测试
|
|
|
func (h *Hub) ping() error {
|
|
|
- if reply, err := redis.String(h.Do("PING")); err != nil || reply != "PONG" {
|
|
|
+ // 避免循环调用,此处不调用已包装好的Get和Do方法
|
|
|
+ var conn redis.Conn
|
|
|
+ if nil != h.pool {
|
|
|
+ conn = h.pool.Get()
|
|
|
+ } else if nil != h.cluster {
|
|
|
+ conn = h.cluster.Get()
|
|
|
+ } else {
|
|
|
+ return ErrRedisConnNil
|
|
|
+ }
|
|
|
+ defer func(conn redis.Conn) {
|
|
|
+ _ = conn.Close()
|
|
|
+ }(conn)
|
|
|
+
|
|
|
+ if reply, err := redis.String(conn.Do("PING")); err != nil || reply != "PONG" {
|
|
|
if err != nil {
|
|
|
h.LOG().Warnf("Can not connect to redis: %s", err.Error())
|
|
|
} else {
|