{"library":"flask-session","code":"import os\nfrom flask import Flask, session, redirect, url_for\nfrom flask_session import Session\nfrom redis import Redis\n\napp = Flask(__name__)\n\n# Configuration for server-side sessions\napp.config[\"SECRET_KEY\"] = os.environ.get(\"FLASK_SECRET_KEY\", \"super-secret-key-that-should-be-random-and-long\")\napp.config[\"SESSION_TYPE\"] = \"redis\"\napp.config[\"SESSION_PERMANENT\"] = False # Set to True for permanent sessions\n\n# Configure Redis client (replace with your Redis connection details)\n# For production, consider using environment variables for host/port/password\napp.config[\"SESSION_REDIS\"] = Redis(host=os.environ.get(\"REDIS_HOST\", \"localhost\"), port=6379, db=0)\n\n# Initialize Flask-Session\nSession(app)\n\n@app.route('/')\ndef index():\n    if 'username' in session:\n        return f'Hello, {session[\"username\"]}! <a href=\"/logout\">Logout</a>'\n    return 'You are not logged in. <a href=\"/login\">Login</a>'\n\n@app.route('/login')\ndef login():\n    # Simulate a login, in a real app this would involve forms and authentication\n    session['username'] = 'testuser'\n    return redirect(url_for('index'))\n\n@app.route('/logout')\ndef logout():\n    session.pop('username', None)\n    return redirect(url_for('index'))\n\nif __name__ == '__main__':\n    app.run(debug=True)","lang":"python","description":"This quickstart demonstrates how to set up Flask-Session with a Redis backend. It configures the Flask application with a secret key (essential for session security) and specifies Redis as the session storage type. The example includes simple routes to set, get, and clear session data, showcasing how `flask.session` is used once `flask_session.Session` is initialized. Remember to install `redis` (`pip install 'flask-session[redis]'`) for this example to work. [3, 8]","tag":null,"tag_description":null,"last_tested":"2026-04-24","results":[{"runtime":"python:3.10-alpine","exit_code":1},{"runtime":"python:3.10-slim","exit_code":1},{"runtime":"python:3.11-alpine","exit_code":1},{"runtime":"python:3.11-slim","exit_code":1},{"runtime":"python:3.12-alpine","exit_code":1},{"runtime":"python:3.12-slim","exit_code":1},{"runtime":"python:3.13-alpine","exit_code":1},{"runtime":"python:3.13-slim","exit_code":1},{"runtime":"python:3.9-alpine","exit_code":1},{"runtime":"python:3.9-slim","exit_code":1}]}