2018-08-15 15:01:38 +08:00
|
|
|
package redis
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/filer2"
|
2018-08-20 06:17:55 +08:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/util"
|
2018-08-20 06:18:37 +08:00
|
|
|
"github.com/go-redis/redis"
|
2018-08-15 15:01:38 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
filer2.Stores = append(filer2.Stores, &RedisClusterStore{})
|
|
|
|
}
|
|
|
|
|
|
|
|
type RedisClusterStore struct {
|
|
|
|
UniversalRedisStore
|
|
|
|
}
|
|
|
|
|
|
|
|
func (store *RedisClusterStore) GetName() string {
|
|
|
|
return "redis_cluster"
|
|
|
|
}
|
|
|
|
|
2018-08-20 06:17:55 +08:00
|
|
|
func (store *RedisClusterStore) Initialize(configuration util.Configuration) (err error) {
|
2019-12-21 12:57:38 +08:00
|
|
|
|
2019-12-22 01:30:51 +08:00
|
|
|
configuration.SetDefault("useReadOnly", true)
|
|
|
|
configuration.SetDefault("routeByLatency", true)
|
|
|
|
|
2018-08-15 15:01:38 +08:00
|
|
|
return store.initialize(
|
|
|
|
configuration.GetStringSlice("addresses"),
|
2019-05-21 00:00:30 +08:00
|
|
|
configuration.GetString("password"),
|
2019-12-21 10:23:01 +08:00
|
|
|
configuration.GetBool("useReadOnly"),
|
|
|
|
configuration.GetBool("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
|
|
|
|
}
|