diff --git a/conf/remote.go b/conf/remote.go index e938e7c..8338b47 100644 --- a/conf/remote.go +++ b/conf/remote.go @@ -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"` } diff --git a/rc/rc.go b/rc/rc.go index a7d99fa..fb16c20 100644 --- a/rc/rc.go +++ b/rc/rc.go @@ -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 }