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