redis_cluster_store.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package redis
  2. import (
  3. "github.com/redis/go-redis/v9"
  4. "github.com/seaweedfs/seaweedfs/weed/filer"
  5. "github.com/seaweedfs/seaweedfs/weed/util"
  6. )
  7. func init() {
  8. filer.Stores = append(filer.Stores, &RedisClusterStore{})
  9. }
  10. type RedisClusterStore struct {
  11. UniversalRedisStore
  12. }
  13. func (store *RedisClusterStore) GetName() string {
  14. return "redis_cluster"
  15. }
  16. func (store *RedisClusterStore) Initialize(configuration util.Configuration, prefix string) (err error) {
  17. configuration.SetDefault(prefix+"useReadOnly", false)
  18. configuration.SetDefault(prefix+"routeByLatency", false)
  19. return store.initialize(
  20. configuration.GetStringSlice(prefix+"addresses"),
  21. configuration.GetString(prefix+"password"),
  22. configuration.GetBool(prefix+"useReadOnly"),
  23. configuration.GetBool(prefix+"routeByLatency"),
  24. )
  25. }
  26. func (store *RedisClusterStore) initialize(addresses []string, password string, readOnly, routeByLatency bool) (err error) {
  27. store.Client = redis.NewClusterClient(&redis.ClusterOptions{
  28. Addrs: addresses,
  29. Password: password,
  30. ReadOnly: readOnly,
  31. RouteByLatency: routeByLatency,
  32. })
  33. return
  34. }