Skip to content

Commit

Permalink
use seperate redis config for storing configs so localhost redis can …
Browse files Browse the repository at this point in the history
…be used for caching
  • Loading branch information
lhridder committed Aug 22, 2022
1 parent c4ad27c commit 7fa05c0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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.
Expand Down
20 changes: 14 additions & 6 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 7fa05c0

Please sign in to comment.