Skip to content

Commit 6f4174b

Browse files
author
mousemin
committed
all: Add Redis configuration parameters
1 parent 5f0513d commit 6f4174b

File tree

5 files changed

+17
-6
lines changed

5 files changed

+17
-6
lines changed

cmd/frontend/main.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,11 @@ func main() {
174174
var cacher frontend.Cacher
175175
if cfg.RedisCacheHost != "" {
176176
addr := cfg.RedisCacheHost + ":" + cfg.RedisCachePort
177-
redisClient = redis.NewClient(&redis.Options{Addr: addr})
177+
redisClient = redis.NewClient(&redis.Options{
178+
Addr: addr,
179+
Password: cfg.RedisCachePassword,
180+
DB: cfg.RedisCacheDB,
181+
})
178182
if err := redisClient.Ping(ctx).Err(); err != nil {
179183
log.Errorf(ctx, "redis at %s: %v", addr, err)
180184
} else {

cmd/worker/main.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,14 @@ func main() {
166166
}
167167

168168
func getCacheRedis(ctx context.Context, cfg *config.Config) *redis.Client {
169-
return getRedis(ctx, cfg.RedisCacheHost, cfg.RedisCachePort, 0, 6*time.Second)
169+
return getRedis(ctx, cfg.RedisCacheHost, cfg.RedisCachePort, cfg.RedisCachePassword, cfg.RedisCacheDB, 0, 6*time.Second)
170170
}
171171

172172
func getBetaCacheRedis(ctx context.Context, cfg *config.Config) *redis.Client {
173-
return getRedis(ctx, cfg.RedisBetaCacheHost, cfg.RedisCachePort, 0, 6*time.Second)
173+
return getRedis(ctx, cfg.RedisBetaCacheHost, cfg.RedisCachePort, cfg.RedisCachePassword, cfg.RedisCacheDB, 0, 6*time.Second)
174174
}
175175

176-
func getRedis(ctx context.Context, host, port string, writeTimeout, readTimeout time.Duration) *redis.Client {
176+
func getRedis(ctx context.Context, host, port, password string, db int, writeTimeout, readTimeout time.Duration) *redis.Client {
177177
if host == "" {
178178
return nil
179179
}
@@ -186,5 +186,7 @@ func getRedis(ctx context.Context, host, port string, writeTimeout, readTimeout
186186
DialTimeout: dialTimeout,
187187
WriteTimeout: writeTimeout,
188188
ReadTimeout: readTimeout,
189+
Password: password,
190+
DB: db,
189191
})
190192
}

doc/config.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Pkgsite uses these environment variables:
44

55
| Environment Variable | Description |
6-
| ------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
6+
|--------------------------------------| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
77
| GO_DISCOVERY_AUTH_VALUES | Set of values that could be set on the AuthHeader, in order to bypass checks by the cache. |
88
| 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. |
99
| 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:
3434
| 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. |
3535
| GO_DISCOVERY_REDIS_HOST | Configuration for redis page cache. |
3636
| GO_DISCOVERY_REDIS_PORT | Configuration for redis page cache. |
37+
| GO_DISCOVERY_REDIS_PASSWORD | Configuration for redis page cache. |
38+
| GO_DISCOVERY_REDIS_DB | Configuration for redis page cache. |
3739
| GO_DISCOVERY_SERVE_STATS | ServeStats determines whether the server has an endpoint that serves statistics for benchmarking or other purposes. |
3840
| 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. |
3941
| 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`. |

internal/config/config.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ type Config struct {
8686
DBPassword string `json:"-" yaml:"-"`
8787

8888
// Configuration for redis page cache.
89-
RedisCacheHost, RedisBetaCacheHost, RedisCachePort string
89+
RedisCacheHost, RedisBetaCacheHost, RedisCachePort, RedisCachePassword string
90+
RedisCacheDB int
9091

9192
// UseProfiler specifies whether to enable Stackdriver Profiler.
9293
UseProfiler bool

internal/config/serverconfig/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ func Init(ctx context.Context) (_ *config.Config, err error) {
152152
RedisCacheHost: os.Getenv("GO_DISCOVERY_REDIS_HOST"),
153153
RedisBetaCacheHost: os.Getenv("GO_DISCOVERY_REDIS_BETA_HOST"),
154154
RedisCachePort: GetEnv("GO_DISCOVERY_REDIS_PORT", "6379"),
155+
RedisCachePassword: GetEnv("GO_DISCOVERY_REDIS_PASSWORD", ""),
156+
RedisCacheDB: GetEnvInt(ctx, "GO_DISCOVERY_REDIS_DB", 0),
155157
Quota: config.QuotaSettings{
156158
Enable: os.Getenv("GO_DISCOVERY_ENABLE_QUOTA") == "true",
157159
QPS: GetEnvInt(ctx, "GO_DISCOVERY_QUOTA_QPS", 10),

0 commit comments

Comments
 (0)