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.3 KiB

  1. package redis_lua
  2. import (
  3. "github.com/chrislusf/seaweedfs/weed/filer"
  4. "github.com/chrislusf/seaweedfs/weed/util"
  5. "github.com/go-redis/redis/v8"
  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. }