2018-08-15 15:01:38 +08:00
|
|
|
package redis
|
|
|
|
|
|
|
|
import (
|
2021-01-11 18:30:19 +08:00
|
|
|
"github.com/go-redis/redis/v8"
|
2022-07-29 15:17:28 +08:00
|
|
|
"github.com/seaweedfs/seaweedfs/weed/filer"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/util"
|
2018-08-15 15:01:38 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2020-09-01 15:21:19 +08:00
|
|
|
filer.Stores = append(filer.Stores, &RedisClusterStore{})
|
2018-08-15 15:01:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
type RedisClusterStore struct {
|
|
|
|
UniversalRedisStore
|
|
|
|
}
|
|
|
|
|
|
|
|
func (store *RedisClusterStore) GetName() string {
|
|
|
|
return "redis_cluster"
|
|
|
|
}
|
|
|
|
|
2020-01-30 01:09:55 +08:00
|
|
|
func (store *RedisClusterStore) Initialize(configuration util.Configuration, prefix string) (err error) {
|
2019-12-21 12:57:38 +08:00
|
|
|
|
2021-01-08 17:12:44 +08:00
|
|
|
configuration.SetDefault(prefix+"useReadOnly", false)
|
|
|
|
configuration.SetDefault(prefix+"routeByLatency", false)
|
2019-12-22 01:30:51 +08:00
|
|
|
|
2018-08-15 15:01:38 +08:00
|
|
|
return store.initialize(
|
2020-01-30 01:09:55 +08:00
|
|
|
configuration.GetStringSlice(prefix+"addresses"),
|
|
|
|
configuration.GetString(prefix+"password"),
|
|
|
|
configuration.GetBool(prefix+"useReadOnly"),
|
|
|
|
configuration.GetBool(prefix+"routeByLatency"),
|
2018-08-15 15:01:38 +08:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-12-18 23:34:19 +08:00
|
|
|
func (store *RedisClusterStore) initialize(addresses []string, password string, readOnly, routeByLatency bool) (err error) {
|
2018-08-15 15:01:38 +08:00
|
|
|
store.Client = redis.NewClusterClient(&redis.ClusterOptions{
|
2019-12-18 23:34:19 +08:00
|
|
|
Addrs: addresses,
|
|
|
|
Password: password,
|
|
|
|
ReadOnly: readOnly,
|
|
|
|
RouteByLatency: routeByLatency,
|
2018-08-15 15:01:38 +08:00
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|