2020-06-15 18:20:18 +02:00
|
|
|
diff --git a/cmd/chartmuseum/main.go b/cmd/chartmuseum/main.go
|
2021-05-11 14:48:53 +02:00
|
|
|
index 8fd7349..eb67ddf 100644
|
2020-06-15 18:20:18 +02:00
|
|
|
--- a/cmd/chartmuseum/main.go
|
|
|
|
+++ b/cmd/chartmuseum/main.go
|
2021-05-11 14:48:53 +02:00
|
|
|
@@ -282,12 +282,23 @@ func storeFromConfig(conf *config.Config) cache.Store {
|
2020-06-15 18:20:18 +02:00
|
|
|
switch cacheFlag {
|
|
|
|
case "redis":
|
|
|
|
store = redisCacheFromConfig(conf)
|
|
|
|
+ case "redis_sentinel":
|
|
|
|
+ store = redisSentinelCacheFromConfig(conf)
|
|
|
|
default:
|
|
|
|
crash("Unsupported cache store: ", cacheFlag)
|
|
|
|
}
|
|
|
|
|
2021-05-11 14:48:53 +02:00
|
|
|
return store
|
|
|
|
}
|
2020-06-15 18:20:18 +02:00
|
|
|
+func redisSentinelCacheFromConfig(conf *config.Config) cache.Store {
|
|
|
|
+ crashIfConfigMissingVars(conf, []string{"cache.redis.addr", "cache.redis.mastername"})
|
|
|
|
+ return cache.Store(cache.NewRedisSentinelStore(
|
|
|
|
+ conf.GetString("cache.redis.mastername"),
|
|
|
|
+ strings.Split(conf.GetString("cache.redis.addr"), ","),
|
|
|
|
+ conf.GetString("cache.redis.password"),
|
|
|
|
+ conf.GetInt("cache.redis.db"),
|
|
|
|
+ ))
|
|
|
|
+}
|
2021-05-11 14:48:53 +02:00
|
|
|
|
|
|
|
func redisCacheFromConfig(conf *config.Config) cache.Store {
|
|
|
|
crashIfConfigMissingVars(conf, []string{"cache.redis.addr"})
|
2020-06-15 18:20:18 +02:00
|
|
|
diff --git a/pkg/cache/redis_sentinel.go b/pkg/cache/redis_sentinel.go
|
|
|
|
new file mode 100644
|
|
|
|
index 0000000..0c73427
|
|
|
|
--- /dev/null
|
|
|
|
+++ b/pkg/cache/redis_sentinel.go
|
|
|
|
@@ -0,0 +1,18 @@
|
|
|
|
+package cache
|
|
|
|
+
|
|
|
|
+import (
|
|
|
|
+ "github.com/go-redis/redis"
|
|
|
|
+)
|
|
|
|
+
|
|
|
|
+// NewRedisStore creates a new RedisStore
|
|
|
|
+func NewRedisSentinelStore(masterName string, sentinelAddrs []string, password string, db int) *RedisStore {
|
|
|
|
+ store := &RedisStore{}
|
|
|
|
+ redisClientOptions := &redis.FailoverOptions{
|
|
|
|
+ MasterName: masterName,
|
|
|
|
+ SentinelAddrs: sentinelAddrs,
|
|
|
|
+ Password: password,
|
|
|
|
+ DB: db,
|
|
|
|
+ }
|
|
|
|
+ store.Client = redis.NewFailoverClient(redisClientOptions)
|
|
|
|
+ return store
|
|
|
|
+}
|
|
|
|
diff --git a/pkg/config/vars.go b/pkg/config/vars.go
|
2021-05-11 14:48:53 +02:00
|
|
|
index 638eb49..4f036c9 100644
|
2020-06-15 18:20:18 +02:00
|
|
|
--- a/pkg/config/vars.go
|
|
|
|
+++ b/pkg/config/vars.go
|
2021-05-11 14:48:53 +02:00
|
|
|
@@ -246,10 +246,19 @@ var configVars = map[string]configVar{
|
2020-06-15 18:20:18 +02:00
|
|
|
Default: "",
|
|
|
|
CLIFlag: cli.StringFlag{
|
|
|
|
Name: "cache-redis-addr",
|
|
|
|
- Usage: "address of Redis service (host:port)",
|
|
|
|
+ Usage: "address of Redis service (host:port), addresses of Redis+Sentinel service (host1:port1,host2:port2)",
|
|
|
|
EnvVar: "CACHE_REDIS_ADDR",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
+ "cache.redis.mastername": {
|
|
|
|
+ Type: stringType,
|
|
|
|
+ Default: "",
|
|
|
|
+ CLIFlag: cli.StringFlag{
|
|
|
|
+ Name: "cache-redis-mastername",
|
|
|
|
+ Usage: "address of Redis+Sentinel mastername",
|
|
|
|
+ EnvVar: "CACHE_REDIS_MASTERNAME",
|
|
|
|
+ },
|
|
|
|
+ },
|
|
|
|
"cache.redis.password": {
|
|
|
|
Type: stringType,
|
|
|
|
Default: "",
|