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.

49 lines
1.4 KiB

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