feat: add redis cluster mode in option (#1178)

Signed-off-by: rfyiamcool <rfyiamcool@163.com>
pull/1183/head
fengyun.rui 1 year ago committed by GitHub
parent d8dbcbbec6
commit 8b649a55a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -224,6 +224,7 @@ config/config.yaml 文件为存储组件提供了详细的配置说明。
```
redis:
clusterMode: false #是否为 redis cluster 模式
address: [ 127.0.0.1:16379 ] #地址
username: #用户名
password: openIM123 #密码

@ -75,6 +75,7 @@ type configStruct struct {
} `yaml:"mongo"`
Redis struct {
ClusterMode bool `yaml:"clusterMode"`
Address []string `yaml:"address"`
Username string `yaml:"username"`
Password string `yaml:"password"`

@ -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
}

Loading…
Cancel
Save