redis_cluster_store.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package redis_lua
  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, &RedisLuaClusterStore{})
  9. }
  10. type RedisLuaClusterStore struct {
  11. UniversalRedisLuaStore
  12. }
  13. func (store *RedisLuaClusterStore) GetName() string {
  14. return "redis_lua_cluster"
  15. }
  16. func (store *RedisLuaClusterStore) 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 *RedisLuaClusterStore) 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. }