From 8e50477ef689fde33df7b8db05cd657e762429a9 Mon Sep 17 00:00:00 2001 From: "huangqing.zhu" Date: Wed, 21 Feb 2024 11:22:46 +0800 Subject: [PATCH] =?UTF-8?q?fix(resp3):=20=E5=BD=93=E4=B8=8D=E6=94=AF?= =?UTF-8?q?=E6=8C=81=20cache=20=E6=97=B6=EF=BC=8C=E8=AE=BE=E7=BD=AE=20Disa?= =?UTF-8?q?bleCache=20=E4=B8=BA=20true=EF=BC=8C=E9=87=8D=E8=BF=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- redis_resp.go | 6 ++++++ redis_resp3.go | 15 +-------------- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/redis_resp.go b/redis_resp.go index 8c4534f..611ae2e 100644 --- a/redis_resp.go +++ b/redis_resp.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "github.com/redis/rueidis" "regexp" "strings" "sync" @@ -122,6 +123,11 @@ func (c *client) connect() error { err = fmt.Errorf("unknown RESP version, %s", c.v.GetResp()) } if err != nil { + if strings.Contains(err.Error(), rueidis.ErrNoCache.Error()) { + warning(fmt.Sprintf("%v, resp2, reconnect...", err)) + c.v.ApplyOption(WithResp(RESP2)) + return c.connect() + } return err } // 初始化 diff --git a/redis_resp3.go b/redis_resp3.go index a09624c..c34a686 100644 --- a/redis_resp3.go +++ b/redis_resp3.go @@ -44,22 +44,9 @@ func confVisitor2ClientOption(v ConfVisitor) rueidis.ClientOption { } } -func newResp3Client(opts rueidis.ClientOption) (rueidis.Client, error) { - cmd, err := rueidis.NewClient(opts) - if err == nil { - return cmd, nil - } - if strings.Contains(err.Error(), rueidis.ErrNoCache.Error()) { - opts.DisableCache = true - warning(fmt.Sprintf("%v, ClientOption.DisableCache=true, reconnect...", rueidis.ErrNoCache)) - return newResp3Client(opts) - } - return nil, err -} - func connectResp3(v ConfVisitor, h handler) (*resp3, error) { opts := confVisitor2ClientOption(v) - cmd, err := newResp3Client(opts) + cmd, err := rueidis.NewClient(opts) if err != nil { return nil, err }