|
|
|
@ -39,7 +39,7 @@ func NewRedis() (redis.UniversalClient, error) {
|
|
|
|
|
}
|
|
|
|
|
specialerror.AddReplace(redis.Nil, errs.ErrRecordNotFound)
|
|
|
|
|
var rdb redis.UniversalClient
|
|
|
|
|
if len(config.Config.Redis.Address) > 1 {
|
|
|
|
|
if len(config.Config.Redis.Address) > 1 || config.Config.Redis.ClusterMode {
|
|
|
|
|
rdb = redis.NewClusterClient(&redis.ClusterOptions{
|
|
|
|
|
Addrs: config.Config.Redis.Address,
|
|
|
|
|
Username: config.Config.Redis.Username,
|
|
|
|
@ -58,12 +58,13 @@ func NewRedis() (redis.UniversalClient, error) {
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var err error = nil
|
|
|
|
|
var err error
|
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
|
|
|
|
|
defer cancel()
|
|
|
|
|
err = rdb.Ping(ctx).Err()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("redis ping %w", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return rdb, err
|
|
|
|
|
}
|
|
|
|
|