Skip to content

Commit

Permalink
Add db_index option to Redis cache configuration (#380)
Browse files Browse the repository at this point in the history
* Add db_index option to Redis cache configuration

* Clarify db_index use in Redis config docs

---------

Co-authored-by: solodovnikov_ny <solodovnikov_ny@magnit.ru>
  • Loading branch information
DeanNeaht and solodovnikov_ny authored Jan 3, 2024
1 parent 0525643 commit 50817d1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
5 changes: 5 additions & 0 deletions clients/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

Expand Down

0 comments on commit 50817d1

Please sign in to comment.