Add Docker instructions for "Using a separate Redis for the Rails cache" (#629)

This commit is contained in:
Stanislas 2018-08-23 20:26:38 +01:00 committed by Eugen Rochko
parent a0b4ac658e
commit 34d9b15b74
1 changed files with 30 additions and 0 deletions

View File

@ -169,3 +169,33 @@ index 0b50542..1d3fac6 100644
Redis is used widely throughout the application, but some uses are more important than others. Home feeds, list feeds, and Sidekiq queues as well as the streaming API are backed by Redis and that's important data you wouldn't want to lose (even though the loss can be survived, unlike the loss of the PostgreSQL database - never lose that!). However, Redis is also used for volatile cache. If you are at a stage of scaling up where you are worried if your Redis can handle everything, you can use a different Redis database for the cache. In the environment, you can specify `CACHE_REDIS_URL` or individual parts like `CACHE_REDIS_HOST`, `CACHE_REDIS_PORT` etc. Unspecified parts fallback to the same values as without the cache prefix.
As far as configuring the Redis database goes, basically you can get rid of background saving to disk, since it doesn't matter if the data gets lost on restart and you can save some disk I/O on that. You can also add a maximum memory limit and a key eviction policy, for that, see this guide: [Using Redis as an LRU cache](https://redis.io/topics/lru-cache)
With Docker, here's how you would do it with `docker-compose`:
```yaml
redis:
image: redis:4.0-alpine
restart: always
networks:
- internal_network
volumes:
- ./redis:/data
redis_cache:
image: redis:4.0-alpine
restart: always
networks:
- internal_network
command: redis-server --save ""
```
The first Redis is the one you're used to run, and the second one is for the Rails cache. As we don't want it to save to disk, we specify `redis-server --save ""`, and we don't create any volume.
Then your `.env.production` should look like this:
```
REDIS_HOST=redis
REDIS_PORT=6379
CACHE_REDIS_HOST=redis_cache
CACHE_REDIS_PORT=6379
```