Reputation: 2840
import config
from flask import Flask
from flask_redis import Redis
from werkzeug.contrib.fixers import ProxyFix
app = Flask(__name__)
redis_store = Redis(app)
app.debug = config.DEBUG
app.redis_url = config.REDIS_URL
@app.route('/')
def index():
return redis_store.ping()
app.wsgi_app = ProxyFix(app.wsgi_app)
if __name__ == '__main__':
app.run()
config.py
DEBUG = True
REDIS_URL = "redis://:123@localhost:6379/0"
/etc/redis/redis.conf
...
requirepass 123
ERROR:
raise response
ResponseError: operation not permitted
Seems like the AUTH command is not executed, or something similar. Any idea about the possible problem?
Upvotes: 0
Views: 529
Reputation: 20709
According to its README, Flask-Redis looks for a key called REDIS_URL
as part of the Flask config.
Configuration
Your configuration should be declared within your Flask config. You can declare via a Redis URL containing the database
REDIS_URL = "redis://:password@localhost:6379/0"
Without setting that redis_store
will just use the default settings, which won't include your password.
app = Flask(__name__)
app.config['REDIS_URL'] = config.REDIS_URL
redis_store = Redis(app)
Upvotes: 2