redis_cluster_store.go 1.3 KB

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