Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add db_index option to Redis cache configuration #380

Merged
merged 2 commits into from
Jan 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions clients/redis.go
Original file line number Diff line number Diff line change
@@ -16,6 +16,11 @@ func NewRedisClient(cfg config.RedisCacheConfig) (redis.UniversalClient, error)
MaxRetries: 7, // default value = 3, since MinRetryBackoff = 8 msec & MinRetryBackoff = 512 msec
// the redis client will wait up to 1016 msec btw the 7 tries
}

if len(cfg.Addresses) == 1 {
options.DB = cfg.DBIndex
}

if len(cfg.CertFile) != 0 || len(cfg.KeyFile) != 0 {
tlsConfig, err := cfg.TLS.BuildTLSConfig(nil)
if err != nil {
1 change: 1 addition & 0 deletions config/README.md
Original file line number Diff line number Diff line change
@@ -111,6 +111,7 @@ redis:
- <string> # example "localhost:6379"
username: <string>
password: <string>
db_index: <int> | default = 0 [optional] # This option is only applicable for non-clustered Redis instance.

# Expiration time for cached responses.
expire: <duration>
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
@@ -949,6 +949,7 @@ type RedisCacheConfig struct {
Username string `yaml:"username,omitempty"`
Password string `yaml:"password,omitempty"`
Addresses []string `yaml:"addresses"`
DBIndex int `yaml:"db_index,omitempty"`
XXX map[string]interface{} `yaml:",inline"`
}