Flask redis
Use this git repo as a reference implementation.
The above repo contains a .sb.yml
file which is a specification of the entire app’s configuration. Check .sb.yml file for more information.
This will implement a simple endpoint in Flask which will increment a counter everytime the page is loaded in the browser.
It uses Redis to keep track of the count.
Preparing your code
Fetch the Redis credentials from environment variables in the app.
.sb.yml
The environment variables are staple Flask environment variables needed to run your Flask app.
In addition to this, we create a redis service called data-cache
and attach it to the app using separate variables.
Procfile
We add a Procfile
which is the idomatic way to run Flask apps.
web
is the name of the default process which will run in the app container.
Deploying this app will create a Flask server and a redis cache.