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.

45 lines
1.3 KiB

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