Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support external redis host and using 127.0.0.1 as default #196

Merged
merged 4 commits into from
Jul 3, 2024
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
7 changes: 5 additions & 2 deletions platform/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ func doMain(ctx context.Context) error {
setEnvDefault("REACT_APP_LOCALE", "en")

// Migrate from mgmt.
setEnvDefault("REDIS_DATABASE", "0")
setEnvDefault("REDIS_HOST", "127.0.0.1")
setEnvDefault("REDIS_PORT", "6379")
setEnvDefault("MGMT_LISTEN", "2022")

Expand All @@ -128,15 +130,16 @@ func doMain(ctx context.Context) error {

logger.Tf(ctx, "load .env as MGMT_PASSWORD=%vB, "+
"SRS_PLATFORM_SECRET=%vB, CLOUD=%v, REGION=%v, SOURCE=%v, SRT_PORT=%v, RTC_PORT=%v, "+
"NODE_ENV=%v, LOCAL_RELEASE=%v, REDIS_PASSWORD=%vB, REDIS_PORT=%v, RTMP_PORT=%v, "+
"NODE_ENV=%v, LOCAL_RELEASE=%v, REDIS_DATABASE=%v, REDIS_HOST=%v, REDIS_PASSWORD=%vB, REDIS_PORT=%v, RTMP_PORT=%v, "+
"PUBLIC_URL=%v, BUILD_PATH=%v, REACT_APP_LOCALE=%v, PLATFORM_LISTEN=%v, HTTP_PORT=%v, "+
"REGISTRY=%v, MGMT_LISTEN=%v, HTTPS_LISTEN=%v, AUTO_SELF_SIGNED_CERTIFICATE=%v, "+
"NAME_LOOKUP=%v, PLATFORM_DOCKER=%v, SRS_FORWARD_LIMIT=%v, SRS_VLIVE_LIMIT=%v, "+
"SRS_CAMERA_LIMIT=%v",
len(envMgmtPassword()), len(envApiSecret()), envCloud(),
envRegion(), envSource(), envSrtListen(), envRtcListen(),
envNodeEnv(), envLocalRelease(),
len(envRedisPassword()), envRedisPort(), envRtmpPort(), envPublicUrl(),
envRedisDatabase(), envRedisHost(), len(envRedisPassword()), envRedisPort(),
envRtmpPort(), envPublicUrl(),
envBuildPath(), envReactAppLocale(), envPlatformListen(), envHttpPort(),
envRegistry(), envMgmtListen(), envHttpListen(),
envSelfSignedCertificate(), envNameLookup(),
Expand Down
18 changes: 15 additions & 3 deletions platform/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,14 @@ func envRedisPort() string {
return os.Getenv("REDIS_PORT")
}

func envRedisHost() string {
winlinvip marked this conversation as resolved.
Show resolved Hide resolved
return os.Getenv("REDIS_HOST")
}

func envRedisDatabase() string {
return os.Getenv("REDIS_DATABASE")
}

func envRtmpPort() string {
return os.Getenv("RTMP_PORT")
}
Expand Down Expand Up @@ -481,11 +489,15 @@ var rdb *redis.Client

// InitRdb create and init global rdb, which is a redis client.
func InitRdb() error {
addr := "127.0.0.1"
redisDatabase, err := strconv.Atoi(envRedisDatabase())
if err != nil {
return errors.Wrapf(err, "invalid REDIS_DATABASE %v", envRedisDatabase())
}

rdb = redis.NewClient(&redis.Options{
Addr: fmt.Sprintf("%v:%v", addr, envRedisPort()),
Addr: fmt.Sprintf("%v:%v", envRedisHost(), envRedisPort()),
Password: envRedisPassword(),
DB: 0,
DB: redisDatabase,
})
return nil
}
Expand Down
Loading