Skip to content

Commit 50817d1

Browse files
DeanNeahtsolodovnikov_ny
andauthored
Add db_index option to Redis cache configuration (#380)
* Add db_index option to Redis cache configuration * Clarify db_index use in Redis config docs --------- Co-authored-by: solodovnikov_ny <[email protected]>
1 parent 0525643 commit 50817d1

File tree

3 files changed

+7
-0
lines changed

3 files changed

+7
-0
lines changed

clients/redis.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ func NewRedisClient(cfg config.RedisCacheConfig) (redis.UniversalClient, error)
1616
MaxRetries: 7, // default value = 3, since MinRetryBackoff = 8 msec & MinRetryBackoff = 512 msec
1717
// the redis client will wait up to 1016 msec btw the 7 tries
1818
}
19+
20+
if len(cfg.Addresses) == 1 {
21+
options.DB = cfg.DBIndex
22+
}
23+
1924
if len(cfg.CertFile) != 0 || len(cfg.KeyFile) != 0 {
2025
tlsConfig, err := cfg.TLS.BuildTLSConfig(nil)
2126
if err != nil {

config/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ redis:
111111
- <string> # example "localhost:6379"
112112
username: <string>
113113
password: <string>
114+
db_index: <int> | default = 0 [optional] # This option is only applicable for non-clustered Redis instance.
114115

115116
# Expiration time for cached responses.
116117
expire: <duration>

config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -949,6 +949,7 @@ type RedisCacheConfig struct {
949949
Username string `yaml:"username,omitempty"`
950950
Password string `yaml:"password,omitempty"`
951951
Addresses []string `yaml:"addresses"`
952+
DBIndex int `yaml:"db_index,omitempty"`
952953
XXX map[string]interface{} `yaml:",inline"`
953954
}
954955

0 commit comments

Comments
 (0)