Skip to content
Snippets Groups Projects
Commit 8b85a882 authored by Travis Ralston's avatar Travis Ralston
Browse files
parent d08e0063
No related branches found
No related tags found
No related merge requests found
...@@ -7,10 +7,19 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ...@@ -7,10 +7,19 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
## [Unreleased] ## [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
* Added support for setting the Redis database number. * 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 ## [1.2.9] - December 22nd, 2021
### Deprecation notices ### Deprecation notices
......
...@@ -576,28 +576,28 @@ featureSupport: ...@@ -576,28 +576,28 @@ featureSupport:
# so it can be mapped to a volume. # so it can be mapped to a volume.
repoPath: "./ipfs" repoPath: "./ipfs"
# Support for redis as a cache mechanism # Support for redis as a cache mechanism
# #
# Note: Enabling Redis support will mean that the existing cache mechanism will do nothing. # Note: Enabling Redis support will mean that the existing cache mechanism will do nothing.
# It can be safely disabled once Redis support is enabled. # 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. # See docs/redis.md for more information on how this works and how to set it up.
redis: redis:
# Whether or not use Redis instead of in-process caching. # Whether or not use Redis instead of in-process caching.
enabled: false enabled: false
# The database number to use. Leave at zero if using a dedicated Redis instance. # The database number to use. Leave at zero if using a dedicated Redis instance.
databaseNumber: 0 databaseNumber: 0
# The Redis shards that should be used by the media repo in the ring. The names of the # 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 are for your reference and have no bearing on the connection, but must be unique.
shards: shards:
- name: "server1" - name: "server1"
addr: ":7000" addr: ":7000"
- name: "server2" - name: "server2"
addr: ":7001" addr: ":7001"
- name: "server3" - name: "server3"
addr: ":7002" addr: ":7002"
# Optional sentry (https://sentry.io/) configuration for the media repo # Optional sentry (https://sentry.io/) configuration for the media repo
sentry: sentry:
......
...@@ -19,7 +19,7 @@ func Get() ContentCache { ...@@ -19,7 +19,7 @@ func Get() ContentCache {
lock.Do(func() { lock.Do(func() {
if config.Get().Redis.Enabled { if config.Get().Redis.Enabled {
logrus.Info("Setting up Redis cache") logrus.Info("Setting up Redis cache")
instance = NewRedisCache() instance = NewRedisCache(config.Get().Redis)
} else if config.Get().Features.Redis.Enabled { } else if config.Get().Features.Redis.Enabled {
logrus.Info("Setting up Redis cache") logrus.Info("Setting up Redis cache")
...@@ -27,7 +27,7 @@ func Get() ContentCache { ...@@ -27,7 +27,7 @@ func Get() ContentCache {
logrus.Warn(warnMsg) logrus.Warn(warnMsg)
sentry.CaptureMessage(warnMsg) sentry.CaptureMessage(warnMsg)
instance = NewRedisCache() instance = NewRedisCache(config.Get().Features.Redis)
} else if !config.Get().Downloads.Cache.Enabled { } else if !config.Get().Downloads.Cache.Enabled {
logrus.Warn("Cache is disabled - setting up a dummy instance") logrus.Warn("Cache is disabled - setting up a dummy instance")
instance = NewNoopCache() instance = NewNoopCache()
......
...@@ -2,6 +2,7 @@ package internal_cache ...@@ -2,6 +2,7 @@ package internal_cache
import ( import (
"bytes" "bytes"
"github.com/turt2live/matrix-media-repo/common/config"
"io" "io"
"io/ioutil" "io/ioutil"
...@@ -16,8 +17,8 @@ type RedisCache struct { ...@@ -16,8 +17,8 @@ type RedisCache struct {
redis *redis_cache.RedisCache redis *redis_cache.RedisCache
} }
func NewRedisCache() *RedisCache { func NewRedisCache(conf config.RedisConfig) *RedisCache {
return &RedisCache{redis: redis_cache.NewCache()} return &RedisCache{redis: redis_cache.NewCache(conf)}
} }
func (c *RedisCache) Reset() { func (c *RedisCache) Reset() {
......
...@@ -21,15 +21,15 @@ type RedisCache struct { ...@@ -21,15 +21,15 @@ type RedisCache struct {
ring *redis.Ring ring *redis.Ring
} }
func NewCache() *RedisCache { func NewCache(conf config.RedisConfig) *RedisCache {
addresses := make(map[string]string) addresses := make(map[string]string)
for _, c := range config.Get().Features.Redis.Shards { for _, c := range conf.Shards {
addresses[c.Name] = c.Address addresses[c.Name] = c.Address
} }
ring := redis.NewRing(&redis.RingOptions{ ring := redis.NewRing(&redis.RingOptions{
Addrs: addresses, Addrs: addresses,
DialTimeout: 10 * time.Second, DialTimeout: 10 * time.Second,
DB: config.Get().Features.Redis.DbNum, DB: conf.DbNum,
}) })
logrus.Info("Contacting Redis shards...") logrus.Info("Contacting Redis shards...")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment