Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions engines/redis/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package redis

import (
"context"
"fmt"
"strings"
"time"

Expand All @@ -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 (
Expand Down Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions engines/redis/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading