Skip to content

Commit

Permalink
Add NewCluster util method
Browse files Browse the repository at this point in the history
Signed-off-by: Tamal Saha <[email protected]>
  • Loading branch information
tamalsaha committed Apr 29, 2023
1 parent 3c7919b commit 2f2a7ce
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions pkg/redisdump/cluster.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package redisdump

import (
"fmt"
"net"
"strconv"
"strings"
Expand Down Expand Up @@ -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)))
}

0 comments on commit 2f2a7ce

Please sign in to comment.