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.

42 lines
1.1 KiB

5 years ago
  1. package redis
  2. import (
  3. "github.com/go-redis/redis/v8"
  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. }