Skip to content

Commit

Permalink
fix(resp3): 当不支持 cache 时,设置 DisableCache 为 true,重连
Browse files Browse the repository at this point in the history
  • Loading branch information
huangqing.zhu committed Feb 21, 2024
1 parent 90e0483 commit 8e50477
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
6 changes: 6 additions & 0 deletions redis_resp.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"github.com/redis/rueidis"
"regexp"
"strings"
"sync"
Expand Down Expand Up @@ -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
}
// 初始化
Expand Down
15 changes: 1 addition & 14 deletions redis_resp3.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 8e50477

Please sign in to comment.