From 601bc5bef2b771f2b1e7cb52f8edfacc46390f47 Mon Sep 17 00:00:00 2001 From: Paxx Date: Tue, 2 Jul 2024 11:25:45 +0200 Subject: [PATCH 1/3] added redis address and using 127.0.0.1 as fallback --- platform/utils.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/platform/utils.go b/platform/utils.go index c1a06f33..4402130c 100644 --- a/platform/utils.go +++ b/platform/utils.go @@ -436,6 +436,10 @@ func envRedisPort() string { return os.Getenv("REDIS_PORT") } +func envRedisAddress() string { + return os.Getenv("REDIS_ADDRESS") +} + func envRtmpPort() string { return os.Getenv("RTMP_PORT") } @@ -481,7 +485,11 @@ var rdb *redis.Client // InitRdb create and init global rdb, which is a redis client. func InitRdb() error { - addr := "127.0.0.1" + addr := envRedisAddress() + if addr == "" { + addr = "127.0.0.1" + } + rdb = redis.NewClient(&redis.Options{ Addr: fmt.Sprintf("%v:%v", addr, envRedisPort()), Password: envRedisPassword(), From b6ce3d678326f9b6008a4525fb8ca6794f4e5455 Mon Sep 17 00:00:00 2001 From: Paxx Date: Tue, 2 Jul 2024 12:37:22 +0200 Subject: [PATCH 2/3] updated with redis database and redis host --- platform/main.go | 2 ++ platform/utils.go | 18 +++++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/platform/main.go b/platform/main.go index 008d87df..5e22ce51 100644 --- a/platform/main.go +++ b/platform/main.go @@ -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") diff --git a/platform/utils.go b/platform/utils.go index 4402130c..6f3c48fd 100644 --- a/platform/utils.go +++ b/platform/utils.go @@ -436,8 +436,12 @@ func envRedisPort() string { return os.Getenv("REDIS_PORT") } -func envRedisAddress() string { - return os.Getenv("REDIS_ADDRESS") +func envRedisHost() string { + return os.Getenv("REDIS_HOST") +} + +func envRedisDatabase() string { + return os.Getenv("REDIS_DATABASE") } func envRtmpPort() string { @@ -485,15 +489,15 @@ var rdb *redis.Client // InitRdb create and init global rdb, which is a redis client. func InitRdb() error { - addr := envRedisAddress() - if addr == "" { - addr = "127.0.0.1" + redisDatabase, err := strconv.Atoi(envRedisDatabase()) + if err != nil { + return errors.Wrapf(err, "invalid REDIS_DATABASE") } 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 } From c55486a488cfeb3dc187d92dc5b9b16bf62a8718 Mon Sep 17 00:00:00 2001 From: Paxx Date: Tue, 2 Jul 2024 14:20:35 +0200 Subject: [PATCH 3/3] more clear error after initializing own redis --- platform/main.go | 5 +++-- platform/utils.go | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/platform/main.go b/platform/main.go index 5e22ce51..365b27c3 100644 --- a/platform/main.go +++ b/platform/main.go @@ -130,7 +130,7 @@ 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, "+ @@ -138,7 +138,8 @@ func doMain(ctx context.Context) error { 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(), diff --git a/platform/utils.go b/platform/utils.go index 6f3c48fd..445195d9 100644 --- a/platform/utils.go +++ b/platform/utils.go @@ -491,7 +491,7 @@ var rdb *redis.Client func InitRdb() error { redisDatabase, err := strconv.Atoi(envRedisDatabase()) if err != nil { - return errors.Wrapf(err, "invalid REDIS_DATABASE") + return errors.Wrapf(err, "invalid REDIS_DATABASE %v", envRedisDatabase()) } rdb = redis.NewClient(&redis.Options{