You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.2 KiB

  1. package redis2
  2. import (
  3. "github.com/redis/go-redis/v9"
  4. "github.com/seaweedfs/seaweedfs/weed/filer"
  5. "github.com/seaweedfs/seaweedfs/weed/util"
  6. "time"
  7. )
  8. func init() {
  9. filer.Stores = append(filer.Stores, &Redis2SentinelStore{})
  10. }
  11. type Redis2SentinelStore struct {
  12. UniversalRedis2Store
  13. }
  14. func (store *Redis2SentinelStore) GetName() string {
  15. return "redis2_sentinel"
  16. }
  17. func (store *Redis2SentinelStore) Initialize(configuration util.Configuration, prefix string) (err error) {
  18. return store.initialize(
  19. configuration.GetStringSlice(prefix+"addresses"),
  20. configuration.GetString(prefix+"masterName"),
  21. configuration.GetString(prefix+"username"),
  22. configuration.GetString(prefix+"password"),
  23. configuration.GetInt(prefix+"database"),
  24. )
  25. }
  26. func (store *Redis2SentinelStore) initialize(addresses []string, masterName string, username string, password string, database int) (err error) {
  27. store.Client = redis.NewFailoverClient(&redis.FailoverOptions{
  28. MasterName: masterName,
  29. SentinelAddrs: addresses,
  30. Username: username,
  31. Password: password,
  32. DB: database,
  33. MinRetryBackoff: time.Millisecond * 100,
  34. MaxRetryBackoff: time.Minute * 1,
  35. ReadTimeout: time.Second * 30,
  36. WriteTimeout: time.Second * 5,
  37. })
  38. return
  39. }