Skip to content

Commit

Permalink
feat: 支持 unix 连接方式
Browse files Browse the repository at this point in the history
  • Loading branch information
huangqing.zhu committed Aug 27, 2024
1 parent 9b0a529 commit 62626ac
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
11 changes: 10 additions & 1 deletion connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package redisson

import (
"context"
"crypto/tls"
"errors"
"fmt"
"github.com/alicebob/miniredis/v2"
"github.com/redis/rueidis"
"github.com/redis/rueidis/rueidiscompat"
"net"
"regexp"
"runtime"
"strings"
Expand Down Expand Up @@ -70,7 +72,7 @@ func (c *client) revise(ctx context.Context) error {
}

func confVisitor2ClientOption(v ConfVisitor) rueidis.ClientOption {
return rueidis.ClientOption{
opt := rueidis.ClientOption{
Username: v.GetUsername(),
Password: v.GetPassword(),
InitAddress: v.GetAddrs(),
Expand All @@ -90,6 +92,13 @@ func confVisitor2ClientOption(v ConfVisitor) rueidis.ClientOption {
MasterSet: v.GetMasterName(),
},
}
switch strings.ToLower(v.GetNet()) {
case "unix":
opt.DialFn = func(s string, dialer *net.Dialer, _ *tls.Config) (net.Conn, error) {
return dialer.Dial("unix", s)
}
}
return opt
}

func (c *client) connect() error {
Expand Down
17 changes: 15 additions & 2 deletions gen_conf_optiongen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions option.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type Tester interface {
//go:generate optiongen --new_func=NewConf --xconf=true --empty_composite_nil=true --usage_tag_name=usage
func ConfOptionDeclareWithDefault() any {
return map[string]any{
"Net": "tcp", // @MethodComment(网络类型,tcp/unix)
"AlwaysRESP2": bool(false), // @MethodComment(always uses RESP2, otherwise it will try using RESP3 first)
"Name": "", // @MethodComment(Redis客户端名字)
"MasterName": "", // @MethodComment(Redis Sentinel模式下,master名字)
Expand Down

0 comments on commit 62626ac

Please # to comment.