diff --git a/engines/redis/manager.go b/engines/redis/manager.go index 658197d..ab2df66 100644 --- a/engines/redis/manager.go +++ b/engines/redis/manager.go @@ -21,6 +21,7 @@ package redis import ( "context" + "fmt" "strings" "time" @@ -35,6 +36,9 @@ import ( const ( EnvRootUser = "REDIS_DEFAULT_USER" EnvRootPasswd = "REDIS_DEFAULT_PASSWORD" + + EnvRedisServicePort = "DBCTL_REDIS_SERVICE_PORT" + EnvRedisSentinelServicePort = "DBCTL_REDIS_SENTINEL_SERVICE_PORT" ) var ( @@ -73,6 +77,10 @@ func NewManager(properties engines.Properties) (engines.DBManager, error) { redisPasswd = viper.GetString(EnvRootPasswd) } + if viper.IsSet(EnvRedisServicePort) { + properties["redisHost"] = fmt.Sprintf("127.0.0.1:%s", viper.GetString(EnvRedisServicePort)) + } + managerBase, err := engines.NewDBManagerBase(logger) if err != nil { return nil, err diff --git a/engines/redis/redis.go b/engines/redis/redis.go index 458cf0f..62f39fe 100644 --- a/engines/redis/redis.go +++ b/engines/redis/redis.go @@ -144,10 +144,11 @@ func newClient(s *Settings) redis.UniversalClient { } func newSentinelClient(s *Settings, clusterCompName string) *redis.SentinelClient { - // TODO: use headless service directly - sentinelEnv := fmt.Sprintf("%s_SENTINEL_SERVICE", strings.ToUpper(strings.Join(strings.Split(clusterCompName, "-"), "_"))) - sentinelHost := viper.GetString(fmt.Sprintf("%s_HOST", sentinelEnv)) - sentinelPort := viper.GetString(fmt.Sprintf("%s_PORT", sentinelEnv)) + sentinelHost := fmt.Sprintf("%s-sentinel-headless", clusterCompName) + sentinelPort := "26379" + if viper.IsSet(EnvRedisSentinelServicePort) { + sentinelPort = viper.GetString(EnvRedisSentinelServicePort) + } opt := &redis.Options{ DB: s.DB,