2021-11-25 07:57:03 +00:00
|
|
|
package redis2
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/go-redis/redis/v8"
|
2022-07-29 07:17:28 +00:00
|
|
|
"github.com/seaweedfs/seaweedfs/weed/filer"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/util"
|
2021-11-25 07:57:03 +00:00
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
filer.Stores = append(filer.Stores, &Redis2SentinelStore{})
|
|
|
|
}
|
|
|
|
|
|
|
|
type Redis2SentinelStore struct {
|
|
|
|
UniversalRedis2Store
|
|
|
|
}
|
|
|
|
|
|
|
|
func (store *Redis2SentinelStore) GetName() string {
|
|
|
|
return "redis2_sentinel"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (store *Redis2SentinelStore) Initialize(configuration util.Configuration, prefix string) (err error) {
|
|
|
|
return store.initialize(
|
|
|
|
configuration.GetStringSlice(prefix+"addresses"),
|
|
|
|
configuration.GetString(prefix+"masterName"),
|
|
|
|
configuration.GetString(prefix+"username"),
|
|
|
|
configuration.GetString(prefix+"password"),
|
|
|
|
configuration.GetInt(prefix+"database"),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (store *Redis2SentinelStore) initialize(addresses []string, masterName string, username string, password string, database int) (err error) {
|
|
|
|
store.Client = redis.NewFailoverClient(&redis.FailoverOptions{
|
|
|
|
MasterName: masterName,
|
|
|
|
SentinelAddrs: addresses,
|
|
|
|
Username: username,
|
|
|
|
Password: password,
|
|
|
|
DB: database,
|
|
|
|
MinRetryBackoff: time.Millisecond * 100,
|
|
|
|
MaxRetryBackoff: time.Minute * 1,
|
|
|
|
ReadTimeout: time.Second * 30,
|
|
|
|
WriteTimeout: time.Second * 5,
|
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|