python web app with redis github 1

python web app with redis github

from flask import Flask
from flask_redis import FlaskRedis
from mockredis import MockRedis


def create_app():
    app = Flask(__name__)
    if app.testing:
        redis_store = FlaskRedis.from_custom_provider(MockRedis)
    else:
        redis_store = FlaskRedis()
    redis_store.init_app(app)
    return app

Here is what the above code is Doing:
1. Create a Flask app
2. If the app is in testing mode, create a FlaskRedis instance using the MockRedis provider
3. If the app is not in testing mode, create a FlaskRedis instance using the default provider
4. Initialize the FlaskRedis instance with the Flask app
5. Return the Flask app

Similar Posts