Registry / web-framework / flask-redis

flask-redis

JSON →
library0.4.0pypypi✓ verified 86d ago

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-redis
INSTALL
IMPORT
SIG · FLASK-REDIS
F
flask-redis
web-frameworkpythonv0.4.0
Install
2.6s avg
Import
443ms
Disk
26MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.4.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.463s · 27.3MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 2.6s · import 0.423s · 28MB
26MB installed
● package 26MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

FlaskRedis
from flask_redis import FlaskRedis
Redis
from flask_redis import FlaskRedis
from flask_redis import Redis
The class was renamed from `Redis` to `FlaskRedis` in v0.1.0. Using the old name emits a `DeprecationWarning` and will be removed in future versions.

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.

import os from flask import Flask from flask_redis import FlaskRedis app = Flask(__name__) # Configure Redis URL from environment variable or default app.config['REDIS_URL'] = os.environ.get('REDIS_URL', 'redis://localhost:6379/0') # Initialize Flask-Redis with the app redis_client = FlaskRedis(app) @app.route('/') def index(): try: redis_client.set('mykey', 'hello from flask-redis!') value = redis_client.get('mykey') if value: return f"Value from Redis: {value.decode()}" return "No value found in Redis." except Exception as e: return f"Error connecting to Redis: {e}" if __name__ == '__main__': # Make sure a Redis server is running or set REDIS_URL environment variable print(f"Redis URL: {app.config['REDIS_URL']}") app.run(debug=True)
Debug
Known issues
breakingThe `FlaskRedis.init_app` method no longer accepts a `strict` parameter.
fix
Pass the `strict` flag directly when instantiating `FlaskRedis`: `redis_client = FlaskRedis(app, strict=True)` instead of `redis_client.init_app(app, strict=True)`.
affects: 0.3.0 and later
breakingThe extension is now registered under the lowercase version of its config prefix (default: 'redis') in `app.extensions`.
fix
Access the extension using `app.extensions['redis']` (if using default prefix) or `app.extensions[app.config['REDIS_CONFIG_PREFIX'].lower()]`.
affects: 0.3.0 and later
deprecatedThe class `flask_redis.Redis` was renamed to `flask_redis.FlaskRedis`.
fix
Update your import statement from `from flask_redis import Redis` to `from flask_redis import FlaskRedis` and update class instantiations.
affects: 0.1.0 and later
deprecatedSetting `REDIS_DATABASE` (or equivalent) in config is deprecated in favor of including the database number in `REDIS_URL`.
fix
Use the `REDIS_URL` configuration key (e.g., `redis://localhost:6379/0` for database 0) and remove separate `REDIS_DATABASE` settings.
affects: 0.1.0 and later
Errors
Common errors & fixes
TypeError: init_app() got an unexpected keyword argument 'strict'
Attempting to pass the `strict` parameter to `init_app()` with flask-redis versions 0.3.0 or later.
fix
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)`.
KeyError: 'redis'
Trying to access the Redis client via `app.extensions['redis']` when the extension has not been initialized or the key is incorrect. This can happen if the config prefix was changed, or if running a version older than 0.3.0 (where the key might have been 'REDIS').
fix
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()]`.
DeprecationWarning: flask_redis.Redis is deprecated, use flask_redis.FlaskRedis instead
Using the old class name `Redis` from `flask_redis` module which was renamed.
fix
Change your import statement from `from flask_redis import Redis` to `from flask_redis import FlaskRedis` and update all instances of `Redis(...)` to `FlaskRedis(...)`.
Upgrade
Version history
0.4.0latest on PyPI · released May 29, 2019
Audit
Dependencies
redisrequiredRequired for Redis client functionality.
FlaskrequiredThe core web framework this library extends.
Agent activity
5 hits · last 30 days
node
4
Resources
flask-redis — pip install flask-redis · libregistry