I'm deploying a Flask application on Heroku and need to implement server-side sessions for various reasons, and I can't figure out how to properly set it up. Heroku's docs on how to connect are quite minimalistic:
import os
import redis
r = redis.from_url(os.environ.get("REDIS_URL"))
I'm trying to get this running with the Flask-Session extension. According to their quickstart example:
from flask import Flask, session
from flask.ext.session import Session
app = Flask(__name__)
# Check Configuration section for more details
SESSION_TYPE = 'redis'
app.config.from_object(__name__)
Session(app)
@app.route('/set/')
def set():
session['key'] = 'value'
return 'ok'
I'm confused as to how the two are connected, as the redis module isn't even imported in the latter example. Reading further on the Flask-session page, there's a table of "A list of configuration keys also understood by the extension:", one of which being "SESSION_REDIS", with the description "A redis.Redis instance, default connect to 127.0.0.1:6379". I'm guessing this is the instance (r) from Heroku's docs, but the phrase "keys understood by the extension" gives me no clue regarding what to actually do with it.