Problem
Athens currently always connects to Redis database 0 when using Redis for SingleFlight coordination. There is no way to configure which database index to use.
Current configuration:
singleFlight:
redis:
endpoint: "redis.example.com:6379"
password: "secret"
# No database parameter available
This limitation makes it difficult to run Athens alongside other applications that share the same Redis instance, as all applications compete for keys in database 0.
Proposed Solution
Add a database parameter to the Redis SingleFlight configuration:
singleFlight:
redis:
endpoint: "redis.example.com:6379"
password: "secret"
database: 4 # Specify Redis database index (0-15)
Use Case
We're deploying Athens alongside Harbor in a shared Valkey (Redis-compatible) cluster. Our database allocation looks like:
| Application |
Database |
Purpose |
| Harbor Core |
DB 0 |
Registry metadata cache |
| Harbor JobService |
DB 1 |
Job queue |
| Harbor Registry |
DB 2 |
Layer cache |
| Harbor Trivy |
DB 3 |
Vulnerability scan cache |
| Athens |
DB 0 |
Currently forced to share with Harbor |
Without database selection, Athens shares DB 0 with Harbor Core, which:
- Mixes different application keys in the same keyspace
- Makes troubleshooting difficult (can't separate Athens keys from Harbor keys)
- Prevents setting database-specific Redis policies (memory limits, eviction)
- Reduces operational clarity
Benefits
- Multi-Tenancy: Support shared Redis instances across multiple applications
- Isolation: Clear separation of concerns between applications
- Observability: Database-level metrics via
INFO keyspace command
- Resource Management: Per-database memory limits and eviction policies
- Best Practices: Follows standard Redis operational patterns
Implementation Scope
This feature would require changes in two repositories:
1. Athens Core (gomods/athens)
File: pkg/config/singleflight.go
Add Database field to Redis configuration:
type Redis struct {
Endpoint string `envconfig:"ATHENS_REDIS_ENDPOINT"`
Password string `envconfig:"ATHENS_REDIS_PASSWORD"`
Database int `envconfig:"ATHENS_REDIS_DATABASE" default:"0"` // NEW
LockConfig *RedisLockConfig
}
Redis client initialization (wherever redis.NewClient is called):
client := redis.NewClient(&redis.Options{
Addr: config.Endpoint,
Password: config.Password,
DB: config.Database, // NEW: Use configured database
})
The go-redis v8 library (which Athens uses) already supports the DB option.
2. Athens Helm Chart (gomods/athens-charts)
File: charts/athens-proxy/values.yaml
singleFlight:
redis:
endpoint: ""
password: ""
database: 0 # NEW: Redis database index (0-15), defaults to 0
lockConfig: {}
File: charts/athens-proxy/templates/deployment.yaml
Add environment variable:
{{- if .Values.singleFlight.redis.database }}
- name: ATHENS_REDIS_DATABASE
value: {{ .Values.singleFlight.redis.database | quote }}
{{- end }}
Backwards Compatibility
✅ Fully backwards compatible - The parameter defaults to 0 (Redis default behavior), so existing deployments continue working without any changes.
Alternative Considered: Key Prefixes
We considered adding configurable key prefixes (e.g., athens:lock:{module}) instead of database selection. However, database selection is preferred because:
- Cleaner separation (Redis native feature)
- Better observability (
INFO keyspace shows per-DB stats)
- Simpler implementation (single config parameter)
- Follows standard Redis operational practices
- Explicit isolation guarantees
Related Work
This is similar to issue #111 and PR #112, which improved SingleFlight Redis configuration by moving passwords to secrets. This would be a natural extension of that work.
Documentation Needs
- Update
docs/content/configuration/singleflight.md with database parameter
- Add example to
config.dev.toml
- Update Helm chart README with database configuration example
References
Willingness to Contribute
I'm willing to contribute a PR for this feature if the maintainers are open to it. The implementation is straightforward and I've already mapped out the required changes.
Problem
Athens currently always connects to Redis database 0 when using Redis for SingleFlight coordination. There is no way to configure which database index to use.
Current configuration:
This limitation makes it difficult to run Athens alongside other applications that share the same Redis instance, as all applications compete for keys in database 0.
Proposed Solution
Add a
databaseparameter to the Redis SingleFlight configuration:Use Case
We're deploying Athens alongside Harbor in a shared Valkey (Redis-compatible) cluster. Our database allocation looks like:
Without database selection, Athens shares DB 0 with Harbor Core, which:
Benefits
INFO keyspacecommandImplementation Scope
This feature would require changes in two repositories:
1. Athens Core (
gomods/athens)File:
pkg/config/singleflight.goAdd
Databasefield to Redis configuration:Redis client initialization (wherever
redis.NewClientis called):The go-redis v8 library (which Athens uses) already supports the
DBoption.2. Athens Helm Chart (
gomods/athens-charts)File:
charts/athens-proxy/values.yamlFile:
charts/athens-proxy/templates/deployment.yamlAdd environment variable:
Backwards Compatibility
✅ Fully backwards compatible - The parameter defaults to 0 (Redis default behavior), so existing deployments continue working without any changes.
Alternative Considered: Key Prefixes
We considered adding configurable key prefixes (e.g.,
athens:lock:{module}) instead of database selection. However, database selection is preferred because:INFO keyspaceshows per-DB stats)Related Work
This is similar to issue #111 and PR #112, which improved SingleFlight Redis configuration by moving passwords to secrets. This would be a natural extension of that work.
Documentation Needs
docs/content/configuration/singleflight.mdwith database parameterconfig.dev.tomlReferences
github.com/go-redis/redis/v8which supports database selection viaDBoption: https://pkg.go.dev/github.com/go-redis/redis/v8#OptionsWillingness to Contribute
I'm willing to contribute a PR for this feature if the maintainers are open to it. The implementation is straightforward and I've already mapped out the required changes.