Service needs to be restarted anytime during the app’s lifetime. Online, but also makes the application more resilient if the Redis This is useful at startup while the application comes Loop lets us attempt our request multiple times if the redis service is Note the way the get_hit_count function is written.
In this example, redis is the hostname of the redis container on theĪpplication’s network. route ( '/' ) def hello (): count = get_hit_count () return 'Hello World! I have been seen times. ConnectionError as exc : if retries = 0 : raise exc retries -= 1 time. Redis ( host = 'redis', port = 6379 ) def get_hit_count (): retries = 5 while True : try : return cache. Import time import redis from flask import Flask app = Flask ( _name_ ) cache = redis.