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