MSP-1388 [+] добавлена настройка для sentinel
This commit is contained in:
1 parent
2e2b903463
commit
265dbc6250
2 files changed
+21
-3
No files matched your search
+7
-1
@@ -25,11 +25,17 @@ func init() {
|
||||
type Remote struct {
|
||||
LogLevel log.Level `schemaGen:"logLevel" schema:"Уровень логирования"`
|
||||
Redis struct {
|
||||
Server string `schemaGen:"server" schema:"Адрес сервера redis"`
|
||||
Server string `schemaGen:"server" schema:"Адрес сервера redis, обязателен, если sentinel не указан"`
|
||||
Password string `schemaGen:"password" schema:"Пароль для redis"`
|
||||
DB int `schemaGen:"db" schema:"номер БД в redis"`
|
||||
Prefix string `schemaGen:"prefix" schema:"Префикс ключей для модуля"`
|
||||
DefaultTimeOut time.Duration `schemaGen:"defaultTimeOut" schema:"TTL по умолчанию, в секундах"`
|
||||
RedisSentinel *struct {
|
||||
Addresses []string `schema:"Адреса нод в кластере"`
|
||||
MasterName string `schema:"Имя мастера"`
|
||||
Username string `schema:"Имя пользователя в sentinel"`
|
||||
Password string `schema:"Пароль в sentinel"`
|
||||
} `schema:"Настройки sentinel,обязательна, если redis.server не указан"`
|
||||
} `schemaGen:"redis" schema:"Настройки redis"`
|
||||
}
|
||||
|
||||
|
||||
@@ -41,11 +41,23 @@ func NewRC(cfg conf.Remote, l *log.Adapter) (*RC, error) {
|
||||
l: l,
|
||||
}
|
||||
|
||||
r.cli = redsync.New(goredis.NewPool(goredislib.NewClient(&goredislib.Options{
|
||||
cli := goredislib.NewClient(&goredislib.Options{
|
||||
Addr: cfg.Redis.Server,
|
||||
Password: cfg.Redis.Password,
|
||||
DB: cfg.Redis.DB,
|
||||
})))
|
||||
})
|
||||
|
||||
if cfg.Redis.RedisSentinel != nil {
|
||||
cli = goredislib.NewFailoverClient(&goredislib.FailoverOptions{
|
||||
MasterName: cfg.Redis.RedisSentinel.MasterName,
|
||||
SentinelAddrs: cfg.Redis.RedisSentinel.Addresses,
|
||||
SentinelUsername: cfg.Redis.RedisSentinel.Username,
|
||||
SentinelPassword: cfg.Redis.RedisSentinel.Password,
|
||||
Password: cfg.Redis.Password,
|
||||
})
|
||||
}
|
||||
|
||||
r.cli = redsync.New(goredis.NewPool(cli))
|
||||
|
||||
return &r, nil
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user