Skip to content

Commit

Permalink
Merge pull request #7 from apecloud/support/redis-hostnetwork
Browse files Browse the repository at this point in the history
support: redis hostnetwork
  • Loading branch information
kizuna-lek authored Dec 9, 2024
2 parents aae7062 + 1bec78d commit adf968c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
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

0 comments on commit adf968c

Please sign in to comment.