mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-12-03 02:42:19 +08:00
fix: fix scripts functions upload
Signed-off-by: Xinwei Xiong (cubxxw) <3293172751nss@gmail.com>
This commit is contained in:
parent
97baaacaa7
commit
116c9b37cb
@ -43,12 +43,10 @@ const (
|
|||||||
// defaultCfgPath is the default path of the configuration file.
|
// defaultCfgPath is the default path of the configuration file.
|
||||||
defaultCfgPath = "../../../../../config/config.yaml"
|
defaultCfgPath = "../../../../../config/config.yaml"
|
||||||
minioHealthCheckDuration = 1
|
minioHealthCheckDuration = 1
|
||||||
maxRetry = 10
|
maxRetry = 100
|
||||||
componentStartErrCode = 6000
|
componentStartErrCode = 6000
|
||||||
configErrCode = 6001
|
configErrCode = 6001
|
||||||
mongoConnTimeout = 10 * time.Second
|
mongoConnTimeout = 30 * time.Second
|
||||||
|
|
||||||
redisConnTimeout = 5 * time.Second // Connection timeout for Redis
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -252,8 +250,9 @@ func checkMinio() (string, error) {
|
|||||||
return str, nil
|
return str, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// checkRedis checks the Redis connection with retries and timeout
|
// checkRedis checks the Redis connection
|
||||||
func checkRedis() (string, error) {
|
func checkRedis() (string, error) {
|
||||||
|
// Prioritize environment variables
|
||||||
address := getEnv("REDIS_ADDRESS", strings.Join(config.Config.Redis.Address, ","))
|
address := getEnv("REDIS_ADDRESS", strings.Join(config.Config.Redis.Address, ","))
|
||||||
username := getEnv("REDIS_USERNAME", config.Config.Redis.Username)
|
username := getEnv("REDIS_USERNAME", config.Config.Redis.Username)
|
||||||
password := getEnv("REDIS_PASSWORD", config.Config.Redis.Password)
|
password := getEnv("REDIS_PASSWORD", config.Config.Redis.Password)
|
||||||
@ -262,44 +261,30 @@ func checkRedis() (string, error) {
|
|||||||
redisAddresses := strings.Split(address, ",")
|
redisAddresses := strings.Split(address, ",")
|
||||||
|
|
||||||
var redisClient redis.UniversalClient
|
var redisClient redis.UniversalClient
|
||||||
var err error
|
if len(redisAddresses) > 1 {
|
||||||
|
// Use cluster client for multiple addresses
|
||||||
for attempt := 0; attempt <= maxRetry; attempt++ {
|
redisClient = redis.NewClusterClient(&redis.ClusterOptions{
|
||||||
if len(redisAddresses) > 1 {
|
Addrs: redisAddresses,
|
||||||
// Use cluster client for multiple addresses
|
Username: username,
|
||||||
redisClient = redis.NewClusterClient(&redis.ClusterOptions{
|
Password: password,
|
||||||
Addrs: redisAddresses,
|
})
|
||||||
Username: username,
|
} else {
|
||||||
Password: password,
|
// Use regular client for single address
|
||||||
})
|
redisClient = redis.NewClient(&redis.Options{
|
||||||
} else {
|
Addr: redisAddresses[0],
|
||||||
// Use regular client for single address
|
Username: username,
|
||||||
redisClient = redis.NewClient(&redis.Options{
|
Password: password,
|
||||||
Addr: redisAddresses[0],
|
})
|
||||||
Username: username,
|
|
||||||
Password: password,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), redisConnTimeout)
|
|
||||||
defer cancel()
|
|
||||||
|
|
||||||
// Ping Redis to check connectivity
|
|
||||||
_, err = redisClient.Ping(ctx).Result()
|
|
||||||
if err == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
if attempt < maxRetry {
|
|
||||||
fmt.Printf("Failed to connect to Redis, retrying: %s\n", err)
|
|
||||||
time.Sleep(time.Second * time.Duration(attempt+1)) // Exponential backoff
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return "", err // Wrap or handle the error as needed
|
|
||||||
}
|
}
|
||||||
defer redisClient.Close()
|
defer redisClient.Close()
|
||||||
|
|
||||||
str := "The addr is: " + strings.Join(redisAddresses, ",")
|
// Ping Redis to check connectivity
|
||||||
|
_, err := redisClient.Ping(context.Background()).Result()
|
||||||
|
str := "the addr is:" + strings.Join(redisAddresses, ",")
|
||||||
|
if err != nil {
|
||||||
|
return "", errs.Wrap(errStr(err, str))
|
||||||
|
}
|
||||||
|
|
||||||
return str, nil
|
return str, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user