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