From 3a8706b6c6479a824ee72b5c66bb985649ec7328 Mon Sep 17 00:00:00 2001 From: Runze Cui Date: Tue, 3 Sep 2024 18:48:39 +0800 Subject: [PATCH] always attempt getConn to init the pool first so the following _withConn will have the valid conn to resolve hystrix --- redis.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/redis.go b/redis.go index 22fede1..fc9ff3f 100644 --- a/redis.go +++ b/redis.go @@ -365,6 +365,16 @@ func (c *baseClient) withConn( return err } + // always attempt getConn to init the pool first so the following _withConn will have the valid conn + cn, connerr := c.getConn(ctx) + if connerr != nil { + return connerr + } + + defer func() { + c.releaseConn(ctx, cn, connerr) + }() + err := limiter.Execute(func() error { return c._withConn(ctx, fn) })