diff --git a/CHANGELOG.md b/CHANGELOG.md index b7c05a8c9f69b10363a057ea4adf8a486f1015e9..2514d827c9c4469ae0d20088d8f3ceeb6c2ce483 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,10 +7,19 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ## [Unreleased] +### Deprecation notices + +In a future version (likely the next), the in-memory cache support will be removed. Instead, please use the Redis +caching that is now supported properly by this release, or disable caching if not applicable for your deployment. + ### Added * Added support for setting the Redis database number. +### Fixed + +* Fixed an issue with the Redis config not being recognized at the root level. + ## [1.2.9] - December 22nd, 2021 ### Deprecation notices diff --git a/config.sample.yaml b/config.sample.yaml index b137e81c07600914079029666d3d6a7599b5d051..a69cffcbb6013ce7a3f9c5fe3d80c34c973c9005 100644 --- a/config.sample.yaml +++ b/config.sample.yaml @@ -576,28 +576,28 @@ featureSupport: # so it can be mapped to a volume. repoPath: "./ipfs" - # Support for redis as a cache mechanism - # - # Note: Enabling Redis support will mean that the existing cache mechanism will do nothing. - # It can be safely disabled once Redis support is enabled. - # - # See docs/redis.md for more information on how this works and how to set it up. - redis: - # Whether or not use Redis instead of in-process caching. - enabled: false +# Support for redis as a cache mechanism +# +# Note: Enabling Redis support will mean that the existing cache mechanism will do nothing. +# It can be safely disabled once Redis support is enabled. +# +# See docs/redis.md for more information on how this works and how to set it up. +redis: + # 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: - - name: "server1" - addr: ":7000" - - name: "server2" - addr: ":7001" - - name: "server3" - addr: ":7002" + # 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: + - name: "server1" + addr: ":7000" + - name: "server2" + addr: ":7001" + - name: "server3" + addr: ":7002" # Optional sentry (https://sentry.io/) configuration for the media repo sentry: diff --git a/internal_cache/instance.go b/internal_cache/instance.go index 22bcebb6ce0fde5b84c9e97bbd13588db6d301b6..a786e8ae997f549e4e8549ae3fd54925d5c76c49 100644 --- a/internal_cache/instance.go +++ b/internal_cache/instance.go @@ -19,7 +19,7 @@ func Get() ContentCache { lock.Do(func() { if config.Get().Redis.Enabled { logrus.Info("Setting up Redis cache") - instance = NewRedisCache() + instance = NewRedisCache(config.Get().Redis) } else if config.Get().Features.Redis.Enabled { logrus.Info("Setting up Redis cache") @@ -27,7 +27,7 @@ func Get() ContentCache { logrus.Warn(warnMsg) sentry.CaptureMessage(warnMsg) - instance = NewRedisCache() + instance = NewRedisCache(config.Get().Features.Redis) } else if !config.Get().Downloads.Cache.Enabled { logrus.Warn("Cache is disabled - setting up a dummy instance") instance = NewNoopCache() diff --git a/internal_cache/redis.go b/internal_cache/redis.go index 6d308466187b3d51d07ddc1e00556fae25f4a789..aeb4c2c2712d41ba83841f9e1b5c681c98c0db5b 100644 --- a/internal_cache/redis.go +++ b/internal_cache/redis.go @@ -2,6 +2,7 @@ package internal_cache import ( "bytes" + "github.com/turt2live/matrix-media-repo/common/config" "io" "io/ioutil" @@ -16,8 +17,8 @@ type RedisCache struct { redis *redis_cache.RedisCache } -func NewRedisCache() *RedisCache { - return &RedisCache{redis: redis_cache.NewCache()} +func NewRedisCache(conf config.RedisConfig) *RedisCache { + return &RedisCache{redis: redis_cache.NewCache(conf)} } func (c *RedisCache) Reset() { diff --git a/redis_cache/redis.go b/redis_cache/redis.go index 757c26b81b8671c79a65f819cf7cb06b369fd563..c1294906293b88ac76602942594c732d4632b86b 100644 --- a/redis_cache/redis.go +++ b/redis_cache/redis.go @@ -21,15 +21,15 @@ type RedisCache struct { ring *redis.Ring } -func NewCache() *RedisCache { +func NewCache(conf config.RedisConfig) *RedisCache { addresses := make(map[string]string) - for _, c := range config.Get().Features.Redis.Shards { + for _, c := range conf.Shards { addresses[c.Name] = c.Address } ring := redis.NewRing(&redis.RingOptions{ Addrs: addresses, DialTimeout: 10 * time.Second, - DB: config.Get().Features.Redis.DbNum, + DB: conf.DbNum, }) logrus.Info("Contacting Redis shards...")