diff --git a/cmd/frontend/main.go b/cmd/frontend/main.go index 11bcaa765..ec46f55d2 100644 --- a/cmd/frontend/main.go +++ b/cmd/frontend/main.go @@ -174,7 +174,11 @@ func main() { var cacher frontend.Cacher if cfg.RedisCacheHost != "" { addr := cfg.RedisCacheHost + ":" + cfg.RedisCachePort - redisClient = redis.NewClient(&redis.Options{Addr: addr}) + redisClient = redis.NewClient(&redis.Options{ + Addr: addr, + Password: cfg.RedisCachePassword, + DB: cfg.RedisCacheDB, + }) if err := redisClient.Ping(ctx).Err(); err != nil { log.Errorf(ctx, "redis at %s: %v", addr, err) } else { diff --git a/cmd/worker/main.go b/cmd/worker/main.go index 23831303b..1521feb4f 100644 --- a/cmd/worker/main.go +++ b/cmd/worker/main.go @@ -166,14 +166,14 @@ func main() { } func getCacheRedis(ctx context.Context, cfg *config.Config) *redis.Client { - return getRedis(ctx, cfg.RedisCacheHost, cfg.RedisCachePort, 0, 6*time.Second) + return getRedis(ctx, cfg.RedisCacheHost, cfg.RedisCachePort, cfg.RedisCachePassword, cfg.RedisCacheDB, 0, 6*time.Second) } func getBetaCacheRedis(ctx context.Context, cfg *config.Config) *redis.Client { - return getRedis(ctx, cfg.RedisBetaCacheHost, cfg.RedisCachePort, 0, 6*time.Second) + return getRedis(ctx, cfg.RedisBetaCacheHost, cfg.RedisCachePort, cfg.RedisCachePassword, cfg.RedisCacheDB, 0, 6*time.Second) } -func getRedis(ctx context.Context, host, port string, writeTimeout, readTimeout time.Duration) *redis.Client { +func getRedis(ctx context.Context, host, port, password string, db int, writeTimeout, readTimeout time.Duration) *redis.Client { if host == "" { return nil } @@ -186,5 +186,7 @@ func getRedis(ctx context.Context, host, port string, writeTimeout, readTimeout DialTimeout: dialTimeout, WriteTimeout: writeTimeout, ReadTimeout: readTimeout, + Password: password, + DB: db, }) } diff --git a/doc/config.md b/doc/config.md index 81d280bba..bfe004910 100644 --- a/doc/config.md +++ b/doc/config.md @@ -3,7 +3,7 @@ Pkgsite uses these environment variables: | Environment Variable | Description | -| ------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +|--------------------------------------| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | GO_DISCOVERY_AUTH_VALUES | Set of values that could be set on the AuthHeader, in order to bypass checks by the cache. | | GO_DISCOVERY_CONFIG_BUCKET | Bucket use for dynamic configuration (gs://bucket/object) GO_DISCOVERY_CONFIG_DYNAMIC must be set if GO_DISCOVERY_CONFIG_BUCKET is set. | | GO_DISCOVERY_CONFIG_DYNAMIC | File that experiments are read from. Can be set locally using devtools/cmd/create_experiment_config/main.go. | @@ -34,6 +34,8 @@ Pkgsite uses these environment variables: | GO_DISCOVERY_QUOTA_RECORD_ONLY | Part of QuotaSettings -- Record data about blocking, but do not actually block. This is a \*bool, so we can distinguish "not present" from "false" in an override. | | GO_DISCOVERY_REDIS_HOST | Configuration for redis page cache. | | GO_DISCOVERY_REDIS_PORT | Configuration for redis page cache. | +| GO_DISCOVERY_REDIS_PASSWORD | Configuration for redis page cache. | +| GO_DISCOVERY_REDIS_DB | Configuration for redis page cache. | | GO_DISCOVERY_SERVE_STATS | ServeStats determines whether the server has an endpoint that serves statistics for benchmarking or other purposes. | | GO_DISCOVERY_SERVICE | GAE app service ID. Used for Kubernetes in the private repo. Set in run_local in queue configuration in private repo. Used to identify service in the logs. | | GO_DISCOVERY_TESTDB | When running `go test ./...`, database tests will not run if you don't have postgres running. To run these tests, set `GO_DISCOVERY_TESTDB=true`. | diff --git a/internal/config/config.go b/internal/config/config.go index 2b8f04580..8073f5ea0 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -86,7 +86,8 @@ type Config struct { DBPassword string `json:"-" yaml:"-"` // Configuration for redis page cache. - RedisCacheHost, RedisBetaCacheHost, RedisCachePort string + RedisCacheHost, RedisBetaCacheHost, RedisCachePort, RedisCachePassword string + RedisCacheDB int // UseProfiler specifies whether to enable Stackdriver Profiler. UseProfiler bool diff --git a/internal/config/serverconfig/config.go b/internal/config/serverconfig/config.go index 7b37a70d8..2ebfa913f 100644 --- a/internal/config/serverconfig/config.go +++ b/internal/config/serverconfig/config.go @@ -152,6 +152,8 @@ func Init(ctx context.Context) (_ *config.Config, err error) { RedisCacheHost: os.Getenv("GO_DISCOVERY_REDIS_HOST"), RedisBetaCacheHost: os.Getenv("GO_DISCOVERY_REDIS_BETA_HOST"), RedisCachePort: GetEnv("GO_DISCOVERY_REDIS_PORT", "6379"), + RedisCachePassword: GetEnv("GO_DISCOVERY_REDIS_PASSWORD", ""), + RedisCacheDB: GetEnvInt(ctx, "GO_DISCOVERY_REDIS_DB", 0), Quota: config.QuotaSettings{ Enable: os.Getenv("GO_DISCOVERY_ENABLE_QUOTA") == "true", QPS: GetEnvInt(ctx, "GO_DISCOVERY_QUOTA_QPS", 10),