Skip to content

Commit e32e0cc

Browse files
author
runze.cui
committed
always attempt getConn to init the pool first so the following _withConn will have the valid conn to resolve hystrix
1 parent 346434d commit e32e0cc

File tree

1 file changed

+28
-18
lines changed

1 file changed

+28
-18
lines changed

redis.go

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,16 @@ func (c *baseClient) withConn(
265265
return err
266266
}
267267

268+
// always attempt getConn to init the pool first so the following _withConn will have the valid conn for resolving hystrix
269+
cn, connerr := c.getConn(ctx)
270+
if connerr != nil {
271+
return connerr
272+
}
273+
274+
defer func() {
275+
c.releaseConn(ctx, cn, connerr)
276+
}()
277+
268278
err := limiter.Execute(func() error {
269279
return c._withConn(ctx, fn)
270280
})
@@ -668,26 +678,26 @@ func (c *Client) pubSub() *PubSub {
668678
// subscription may not be active immediately. To force the connection to wait,
669679
// you may call the Receive() method on the returned *PubSub like so:
670680
//
671-
// sub := client.Subscribe(queryResp)
672-
// iface, err := sub.Receive()
673-
// if err != nil {
674-
// // handle error
675-
// }
681+
// sub := client.Subscribe(queryResp)
682+
// iface, err := sub.Receive()
683+
// if err != nil {
684+
// // handle error
685+
// }
676686
//
677-
// // Should be *Subscription, but others are possible if other actions have been
678-
// // taken on sub since it was created.
679-
// switch iface.(type) {
680-
// case *Subscription:
681-
// // subscribe succeeded
682-
// case *Message:
683-
// // received first message
684-
// case *Pong:
685-
// // pong received
686-
// default:
687-
// // handle error
688-
// }
687+
// // Should be *Subscription, but others are possible if other actions have been
688+
// // taken on sub since it was created.
689+
// switch iface.(type) {
690+
// case *Subscription:
691+
// // subscribe succeeded
692+
// case *Message:
693+
// // received first message
694+
// case *Pong:
695+
// // pong received
696+
// default:
697+
// // handle error
698+
// }
689699
//
690-
// ch := sub.Channel()
700+
// ch := sub.Channel()
691701
func (c *Client) Subscribe(ctx context.Context, channels ...string) *PubSub {
692702
pubsub := c.pubSub()
693703
if len(channels) > 0 {

0 commit comments

Comments
 (0)