diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a931fb196a1f6fa48b82add1c82f4d8375907bf..b7c05a8c9f69b10363a057ea4adf8a486f1015e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ## [Unreleased] -*Nothing yet*. +### Added + +* Added support for setting the Redis database number. ## [1.2.9] - December 22nd, 2021 diff --git a/common/config/models_main.go b/common/config/models_main.go index 02bc8ab7257cca09f7e94644bf5e854edfb9905f..6b15b7834962d4a0819d1f849e59dc62fff3aa6f 100644 --- a/common/config/models_main.go +++ b/common/config/models_main.go @@ -92,9 +92,10 @@ type SentryConfig struct { type RedisConfig struct { Enabled bool `yaml:"enabled"` Shards []RedisShardConfig `yaml:"shards,flow"` + DbNum int `default:"0" yaml:"databaseNumber"` } type RedisShardConfig struct { Name string `yaml:"name"` Address string `yaml:"addr"` -} \ No newline at end of file +} diff --git a/config.sample.yaml b/config.sample.yaml index e2aca61847814258b4de4357ea4bee1139517727..b137e81c07600914079029666d3d6a7599b5d051 100644 --- a/config.sample.yaml +++ b/config.sample.yaml @@ -586,6 +586,9 @@ featureSupport: # Whether or not use Redis instead of in-process caching. enabled: false + # The database number to use. Leave at zero if using a dedicated Redis instance. + databaseNumber: 0 + # The Redis shards that should be used by the media repo in the ring. The names of the # shards are for your reference and have no bearing on the connection, but must be unique. shards: diff --git a/redis_cache/redis.go b/redis_cache/redis.go index 76b04c7818e39d901bd4983622572b22e2a3862f..757c26b81b8671c79a65f819cf7cb06b369fd563 100644 --- a/redis_cache/redis.go +++ b/redis_cache/redis.go @@ -27,8 +27,9 @@ func NewCache() *RedisCache { addresses[c.Name] = c.Address } ring := redis.NewRing(&redis.RingOptions{ - Addrs: addresses, + Addrs: addresses, DialTimeout: 10 * time.Second, + DB: config.Get().Features.Redis.DbNum, }) logrus.Info("Contacting Redis shards...")