Flask-Redis is a Flask extension that provides a convenient way to integrate Redis into your Flask applications. It abstracts away the direct management of Redis connections, allowing you to easily access a Redis client instance configured through your Flask app's configuration. The current version is 0.4.0, with the last release in 2019, indicating a maintenance-only or stable state.
pip install flask-redisVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize Flask-Redis with your Flask application and use the Redis client. It sets the Redis URL via application configuration, which can be overridden by an environment variable. The Redis client instance is then directly available for use, typically within request contexts or blueprints.
Pass the `strict` flag directly when instantiating `FlaskRedis`: `redis_client = FlaskRedis(app, strict=True)` instead of `redis_client.init_app(app, strict=True)`.
Access the extension using `app.extensions['redis']` (if using default prefix) or `app.extensions[app.config['REDIS_CONFIG_PREFIX'].lower()]`.
Update your import statement from `from flask_redis import Redis` to `from flask_redis import FlaskRedis` and update class instantiations.
Use the `REDIS_URL` configuration key (e.g., `redis://localhost:6379/0` for database 0) and remove separate `REDIS_DATABASE` settings.
The `strict` parameter should be passed during the `FlaskRedis` instance creation: `redis_client = FlaskRedis(strict=True)` (if not passing `app` initially) or `redis_client = FlaskRedis(app, strict=True)`.
Ensure `FlaskRedis(app)` or `FlaskRedis().init_app(app)` has been called. If using default config, access via `app.extensions['redis']`. If you changed the config prefix, remember it's lowercased: `app.extensions[your_prefix.lower()]`.
Change your import statement from `from flask_redis import Redis` to `from flask_redis import FlaskRedis` and update all instances of `Redis(...)` to `FlaskRedis(...)`.