Skip to content

Commit

Permalink
Merge pull request #369 from wning-vmware/master
Browse files Browse the repository at this point in the history
Use net.JoinHostPort() to support connection to redis pod in IPv6 k8s cluster
  • Loading branch information
ese authored Feb 7, 2022
2 parents a17632e + 52358c0 commit 22e0631
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions service/redis/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package redis
import (
"errors"
"fmt"
"net"
"regexp"
"strconv"
"strings"
Expand Down Expand Up @@ -60,7 +61,7 @@ var (
// GetNumberSentinelsInMemory return the number of sentinels that the requested sentinel has
func (c *client) GetNumberSentinelsInMemory(ip string) (int32, error) {
options := &rediscli.Options{
Addr: fmt.Sprintf("%s:%s", ip, sentinelPort),
Addr: net.JoinHostPort(ip, sentinelPort),
Password: "",
DB: 0,
}
Expand All @@ -87,7 +88,7 @@ func (c *client) GetNumberSentinelsInMemory(ip string) (int32, error) {
// GetNumberSentinelsInMemory return the number of sentinels that the requested sentinel has
func (c *client) GetNumberSentinelSlavesInMemory(ip string) (int32, error) {
options := &rediscli.Options{
Addr: fmt.Sprintf("%s:%s", ip, sentinelPort),
Addr: net.JoinHostPort(ip, sentinelPort),
Password: "",
DB: 0,
}
Expand Down Expand Up @@ -122,7 +123,7 @@ func isSentinelReady(info string) error {
// ResetSentinel sends a sentinel reset * for the given sentinel
func (c *client) ResetSentinel(ip string) error {
options := &rediscli.Options{
Addr: fmt.Sprintf("%s:%s", ip, sentinelPort),
Addr: net.JoinHostPort(ip, sentinelPort),
Password: "",
DB: 0,
}
Expand All @@ -143,7 +144,7 @@ func (c *client) ResetSentinel(ip string) error {
// GetSlaveOf returns the master of the given redis, or nil if it's master
func (c *client) GetSlaveOf(ip, password string) (string, error) {
options := &rediscli.Options{
Addr: fmt.Sprintf("%s:%s", ip, redisPort),
Addr: net.JoinHostPort(ip, redisPort),
Password: password,
DB: 0,
}
Expand All @@ -162,7 +163,7 @@ func (c *client) GetSlaveOf(ip, password string) (string, error) {

func (c *client) IsMaster(ip, password string) (bool, error) {
options := &rediscli.Options{
Addr: fmt.Sprintf("%s:%s", ip, redisPort),
Addr: net.JoinHostPort(ip, redisPort),
Password: password,
DB: 0,
}
Expand All @@ -181,7 +182,7 @@ func (c *client) MonitorRedis(ip, monitor, quorum, password string) error {

func (c *client) MonitorRedisWithPort(ip, monitor, port, quorum, password string) error {
options := &rediscli.Options{
Addr: fmt.Sprintf("%s:%s", ip, sentinelPort),
Addr: net.JoinHostPort(ip, sentinelPort),
Password: "",
DB: 0,
}
Expand Down Expand Up @@ -216,7 +217,7 @@ func (c *client) MonitorRedisWithPort(ip, monitor, port, quorum, password string

func (c *client) MakeMaster(ip string, password string) error {
options := &rediscli.Options{
Addr: fmt.Sprintf("%s:%s", ip, redisPort),
Addr: net.JoinHostPort(ip, redisPort),
Password: password,
DB: 0,
}
Expand All @@ -234,7 +235,7 @@ func (c *client) MakeSlaveOf(ip, masterIP, password string) error {

func (c *client) MakeSlaveOfWithPort(ip, masterIP, masterPort, password string) error {
options := &rediscli.Options{
Addr: fmt.Sprintf("%s:%s", ip, redisPort), // this is IP and Port for the RedisFailover redis
Addr: net.JoinHostPort(ip, redisPort), // this is IP and Port for the RedisFailover redis
Password: password,
DB: 0,
}
Expand All @@ -248,7 +249,7 @@ func (c *client) MakeSlaveOfWithPort(ip, masterIP, masterPort, password string)

func (c *client) GetSentinelMonitor(ip string) (string, string, error) {
options := &rediscli.Options{
Addr: fmt.Sprintf("%s:%s", ip, sentinelPort),
Addr: net.JoinHostPort(ip, sentinelPort),
Password: "",
DB: 0,
}
Expand All @@ -270,7 +271,7 @@ func (c *client) GetSentinelMonitor(ip string) (string, string, error) {

func (c *client) SetCustomSentinelConfig(ip string, configs []string) error {
options := &rediscli.Options{
Addr: fmt.Sprintf("%s:%s", ip, sentinelPort),
Addr: net.JoinHostPort(ip, sentinelPort),
Password: "",
DB: 0,
}
Expand All @@ -291,7 +292,7 @@ func (c *client) SetCustomSentinelConfig(ip string, configs []string) error {

func (c *client) SetCustomRedisConfig(ip string, configs []string, password string) error {
options := &rediscli.Options{
Addr: fmt.Sprintf("%s:%s", ip, redisPort),
Addr: net.JoinHostPort(ip, redisPort),
Password: password,
DB: 0,
}
Expand Down Expand Up @@ -334,7 +335,7 @@ func (c *client) getConfigParameters(config string) (parameter string, value str

func (c *client) SlaveIsReady(ip, password string) (bool, error) {
options := &rediscli.Options{
Addr: fmt.Sprintf("%s:%s", ip, redisPort),
Addr: net.JoinHostPort(ip, redisPort),
Password: password,
DB: 0,
}
Expand Down

0 comments on commit 22e0631

Please sign in to comment.