From 7fa05c0120c002b0090968ffceb2265abcd4103a Mon Sep 17 00:00:00 2001 From: lhridder Date: Tue, 23 Aug 2022 00:43:01 +0200 Subject: [PATCH] use seperate redis config for storing configs so localhost redis can be used for caching --- README.md | 8 ++++++++ config.go | 20 ++++++++++++++------ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index ca73d44..776d85f 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,10 @@ redis: host: localhost pass: db: 0 +configredis: + host: localhost + pass: + db: 0 rejoinMessage: Please rejoin to verify your connection. genericJoinResponse: There is no proxy associated with this domain. Please check your configuration. genericPing: @@ -89,6 +93,10 @@ Values can be left out if they don't deviate from the default, an empty config.y - `host` what redis server to connect to when caching geoip and username lookups. - `DB` what redis db should be used on the redis server. - `pass` what password should be used when logging into the redis server. +- configredis: + - `host` what redis server to connect to when fetching and watching configs. + - `DB` what redis db should be used on the redis server. + - `pass` what password should be used when logging into the redis server. - tableflip: - `enabled` whether or not tableflip should be used. - `pidfile` where the PID file used for tableflip is located. diff --git a/config.go b/config.go index 039ba18..5488368 100644 --- a/config.go +++ b/config.go @@ -87,6 +87,7 @@ type GlobalConfig struct { TrackBandwidth bool `yaml:"trackBandwidth"` UseRedisConfig bool `yaml:"useRedisConfigs"` Redis Redis + ConfigRedis Redis Api Service Prometheus Service GeoIP GeoIP @@ -130,6 +131,11 @@ var DefaultConfig = GlobalConfig{ Pass: "", DB: 0, }, + ConfigRedis: Redis{ + Host: "localhost", + Pass: "", + DB: 0, + }, RejoinMessage: "Please rejoin to verify your connection.", GenericJoinResponse: "There is no proxy associated with this domain. Please check your configuration.", GenericPing: GenericPing{ @@ -522,12 +528,13 @@ func DefaultStatusResponse() protocol.Packet { func LoadProxyConfigsFromRedis() ([]*ProxyConfig, error) { var cfgs []*ProxyConfig + rcfg := Config.ConfigRedis ctx := context.Background() rdb := redis.NewClient(&redis.Options{ - Addr: Config.Redis.Host + ":6379", - Password: Config.Redis.Pass, - DB: Config.Redis.DB, + Addr: rcfg.Host + ":6379", + Password: rcfg.Pass, + DB: rcfg.DB, }) _, err := rdb.Ping(ctx).Result() if err != nil { @@ -569,10 +576,11 @@ func LoadProxyConfigsFromRedis() ([]*ProxyConfig, error) { func WatchRedisConfigs(out chan *ProxyConfig) error { ctx := context.Background() + rcfg := Config.ConfigRedis rdb = redis.NewClient(&redis.Options{ - Addr: Config.Redis.Host + ":6379", - Password: Config.Redis.Pass, - DB: Config.Redis.DB, + Addr: rcfg.Host + ":6379", + Password: rcfg.Pass, + DB: rcfg.DB, }) _, err := rdb.Ping(ctx).Result() if err != nil {