[英]Flask: How to Authenticate with Flask-Redis and Redis
How can I send "AUTH" command to authenticate the connection using Flask-Redis in Flask app? 如何使用Flask应用程序中的Flask-Redis发送“AUTH”命令来验证连接? I know Flask-Redis is just a small wrapper for redis-py but I can't figure out how to handle the authorization.
我知道Flask-Redis只是redis-py的一个小包装器,但我无法弄清楚如何处理授权。
Ok I have found how to solve this. 好的我已经找到了解决这个问题的方法。 You can pass the password in URL, example:
您可以在URL中传递密码,例如:
...
app.config["REDIS_URL"] = 'redis://:password@localhost/0'
redis_db = Redis(app, "REDIS")
...
Do you mean this Flask_Redis: https://pypi.python.org/pypi/Flask-Redis/0.0.5 ? 你的意思是Flask_Redis: https ://pypi.python.org/pypi/Flask-Redis/0.0.5?
If so, there is a better way to handle this than placing it in the URL. 如果是这样,有一种更好的方法来处理它,而不是将其放在URL中。 According to the docs, in your Flask config place the following:
根据文档,在Flask配置中放置以下内容:
REDIS_HOST = "localhost"
REDIS_PASSWORD = "password"
REDIS_PORT = 6379
If placing the config in code, as in your example: 如果将配置放在代码中,如示例中所示:
app.config["REDIS_PASSWORD"] = 'password'
Doing this in the config should be more maintainable and configurable without modifying code. 在配置中执行此操作应该更易于维护和配置,而无需修改代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.