redis_sentinel_store.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package redis_lua
  2. import (
  3. "github.com/go-redis/redis/v8"
  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, &RedisLuaSentinelStore{})
  10. }
  11. type RedisLuaSentinelStore struct {
  12. UniversalRedisLuaStore
  13. }
  14. func (store *RedisLuaSentinelStore) GetName() string {
  15. return "redis_lua_sentinel"
  16. }
  17. func (store *RedisLuaSentinelStore) 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 *RedisLuaSentinelStore) 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. }