0

I want to use redis as cache server in Flask-caching, the config looks like this,

cache = Cache(config={'CACHE_TYPE': 'redis',
                      'CACHE_REDIS_HOST': redis,
                      'CACHE_REDIS_PORT': 6379
                    })

the 'CACHE_REDIS_HOST' should be the container(service) name i defined in my docker-compose.yml, because i want to cache the data in other container.

redis:
    image: "redis:latest"
    ports:
      - '6379:6379'

But it wont work this way.

how can i get to this? Please help, thanks a lot.

Jayden
  • 61
  • 2
  • 5
  • What is the error that you receive? – Michał Krzywański Jun 05 '19 at 12:12
  • @michalk i changed to 'CACHE_REDIS_HOST': "redis", then it works fine:). While, i see in the tutorial and others code that redis image downloaded once in docker-coompose as a container and also list in the requirements.txt of the website container(service), what is the use of the second one, is it neccessary? – Jayden Jun 05 '19 at 13:34
  • 2
    `'CACHE_REDIS_HOST': 'redis'` here redis is the name of the service in `docker-compose`. When you set up containers from compose they are all connected to the default network created by compose. `redis` is in this case the DNS name of redis container and will be resolved to container ip automatically. – Michał Krzywański Jun 05 '19 at 13:38
  • @michalk thank you for the explanation:). that makes sense now – Jayden Jun 05 '19 at 13:51

1 Answers1

0

REDIS = Remote Dictionary Server is an open-source in-memory storage. I think the best way to answer you, is to point you to the main site of Redis. https://redis.io/ Here you can find more infos about it

In your file, it identifies an image part of your container.

SKAL
  • 1
  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 29 '23 at 02:56