{"id":8172,"library":"flask-redis","title":"Flask-Redis Integration","description":"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.","status":"maintenance","version":"0.4.0","language":"en","source_language":"en","source_url":"https://github.com/underyx/flask-redis/","tags":["flask","redis","database","extension"],"install":[{"cmd":"pip install flask-redis","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Required for Redis client functionality.","package":"redis","optional":false},{"reason":"The core web framework this library extends.","package":"Flask","optional":false}],"imports":[{"symbol":"FlaskRedis","correct":"from flask_redis import FlaskRedis"},{"note":"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.","wrong":"from flask_redis import Redis","symbol":"Redis","correct":"from flask_redis import FlaskRedis"}],"quickstart":{"code":"import os\nfrom flask import Flask\nfrom flask_redis import FlaskRedis\n\napp = Flask(__name__)\n\n# Configure Redis URL from environment variable or default\napp.config['REDIS_URL'] = os.environ.get('REDIS_URL', 'redis://localhost:6379/0')\n\n# Initialize Flask-Redis with the app\nredis_client = FlaskRedis(app)\n\n@app.route('/')\ndef index():\n    try:\n        redis_client.set('mykey', 'hello from flask-redis!')\n        value = redis_client.get('mykey')\n        if value:\n            return f\"Value from Redis: {value.decode()}\"\n        return \"No value found in Redis.\"\n    except Exception as e:\n        return f\"Error connecting to Redis: {e}\"\n\nif __name__ == '__main__':\n    # Make sure a Redis server is running or set REDIS_URL environment variable\n    print(f\"Redis URL: {app.config['REDIS_URL']}\")\n    app.run(debug=True)\n","lang":"python","description":"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."},"warnings":[{"fix":"Pass the `strict` flag directly when instantiating `FlaskRedis`: `redis_client = FlaskRedis(app, strict=True)` instead of `redis_client.init_app(app, strict=True)`.","message":"The `FlaskRedis.init_app` method no longer accepts a `strict` parameter.","severity":"breaking","affected_versions":"0.3.0 and later"},{"fix":"Access the extension using `app.extensions['redis']` (if using default prefix) or `app.extensions[app.config['REDIS_CONFIG_PREFIX'].lower()]`.","message":"The extension is now registered under the lowercase version of its config prefix (default: 'redis') in `app.extensions`.","severity":"breaking","affected_versions":"0.3.0 and later"},{"fix":"Update your import statement from `from flask_redis import Redis` to `from flask_redis import FlaskRedis` and update class instantiations.","message":"The class `flask_redis.Redis` was renamed to `flask_redis.FlaskRedis`.","severity":"deprecated","affected_versions":"0.1.0 and later"},{"fix":"Use the `REDIS_URL` configuration key (e.g., `redis://localhost:6379/0` for database 0) and remove separate `REDIS_DATABASE` settings.","message":"Setting `REDIS_DATABASE` (or equivalent) in config is deprecated in favor of including the database number in `REDIS_URL`.","severity":"deprecated","affected_versions":"0.1.0 and later"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"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)`.","cause":"Attempting to pass the `strict` parameter to `init_app()` with flask-redis versions 0.3.0 or later.","error":"TypeError: init_app() got an unexpected keyword argument 'strict'"},{"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()]`.","cause":"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').","error":"KeyError: 'redis'"},{"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(...)`.","cause":"Using the old class name `Redis` from `flask_redis` module which was renamed.","error":"DeprecationWarning: flask_redis.Redis is deprecated, use flask_redis.FlaskRedis instead"}]}