What is the advantage of using the Flask Redis extension in this example...
from flask import Flask, render_template
from flask.ext.redis import Redis
app = Flask(__app__)
app.config['REDIS_HOST'] = 'localhost'
app.config['REDIS_PORT'] = 6379
app.config['REDIS_DB'] = 0
r = Redis(app)
@app.route("/")
def index():
return render_template("index.html", **r.hgetall("temp.index"))
...over a regular Redis connection instance?
from flask import Flask, render_template
import redis
r = redis.Redis()
@app.route("/")
def index():
return render_template("index.html", **r.hgetall("temp.index"))
Current maintainer of the package here, hi!
I think the two (admittedly minor) conveniences that the package provides are:
Integration with Flask's configuration management, so you can organize all your app configuration in the same place. You can add your Redis database URL next to the one for PostgreSQL or whatever you're using, and it'll be picked up automatically when you initialize the FlaskRedis app.
Automatically attaching to your Flask application, so you don't have to keep importing your Redis instance across modules, as it's already always with you, accessible like this: app.extensions['redis']
. But if you want to import it anyway, you can also import the module with import flask.ext.redis
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With