redis_cluster_store.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package redis2
  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, &RedisCluster2Store{})
  9. }
  10. type RedisCluster2Store struct {
  11. UniversalRedis2Store
  12. }
  13. func (store *RedisCluster2Store) GetName() string {
  14. return "redis_cluster2"
  15. }
  16. func (store *RedisCluster2Store) 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. configuration.GetStringSlice(prefix+"superLargeDirectories"),
  25. )
  26. }
  27. func (store *RedisCluster2Store) initialize(addresses []string, password string, readOnly, routeByLatency bool, superLargeDirectories []string) (err error) {
  28. store.Client = redis.NewClusterClient(&redis.ClusterOptions{
  29. Addrs: addresses,
  30. Password: password,
  31. ReadOnly: readOnly,
  32. RouteByLatency: routeByLatency,
  33. })
  34. store.loadSuperLargeDirectories(superLargeDirectories)
  35. return
  36. }