diff --git a/pkg/redisdump/cluster.go b/pkg/redisdump/cluster.go index 8bb7748..f26bffe 100644 --- a/pkg/redisdump/cluster.go +++ b/pkg/redisdump/cluster.go @@ -1,6 +1,7 @@ package redisdump import ( + "fmt" "net" "strconv" "strings" @@ -115,3 +116,21 @@ func GetHosts(s Host, nWorkers int) ([]Host, error) { } return hosts, nil } + +func NewCluster(hosts []Host) (*radix.Cluster, error) { + addrs := make([]string, 0, len(hosts)) + for _, host := range hosts { + addrs = append(addrs, fmt.Sprintf("%s:%d", host.Host, host.Port)) + } + getConnFunc := func(db *uint8) func(network, addr string) (radix.Client, error) { + return func(network, addr string) (radix.Client, error) { + dialOpts, err := redisDialOpts(hosts[0].Username, hosts[0].Password, hosts[0].TlsHandler, db) + if err != nil { + return nil, err + } + + return radix.Dial(network, addr, dialOpts...) + } + } + return radix.NewCluster(addrs, radix.ClusterPoolFunc(getConnFunc(nil))) +}