python-3.xflaskredisrq

No Redis configuration! error for simple flask app using rq-dashboard


rq-dashboard works from the command line, but not integrated into flask.

The simple example from github

from flask import Flask
import rq_dashboard

app = Flask(__name__)
app.config.from_object(rq_dashboard.default_settings)
rq_dashboard.web.setup_rq_connection(app)
app.register_blueprint(rq_dashboard.blueprint, url_prefix="/rq")

@app.route("/")
def hello():
    return "Hello World!"

if __name__ == "__main__":
    app.run()

returns the error below

File "rq_db.py", line 6, in <module>
rq_dashboard.web.setup_rq_connection(app)
/python/site-packages/rq_dashboard/web.py", line 74, in setup_rq_connection
raise RuntimeError("No Redis configuration!")
RuntimeError: No Redis configuration!

I am using rhel8 with Flask 3.0, python 3.11 in a virtual environment, redis 5.0.3, redis-py 5.0.1, rq 1.15.1, rq-dashboard 0.6.7 and mod_wsgi


Solution

  • Even though I am using the default redis url, I needed to specify it in the Flask app.

    Working code is:

    from flask import Flask
    import rq_dashboard
    
    app = Flask(__name__)
    app.config.from_object(rq_dashboard.default_settings)
    app.config["RQ_DASHBOARD_REDIS_URL"] = "redis://127.0.0.1:6379"
    rq_dashboard.web.setup_rq_connection(app)
    app.register_blueprint(rq_dashboard.blueprint, url_prefix="/rq")
    
    @app.route("/")
    def hello():
        return "Hello World!"
    
    if __name__ == "__main__":
        app.run()