python Flask 如何设置远程地址 REDIS_URL 写一个例子给我
时间: 2023-05-15 07:06:23 浏览: 201
可以使用 Flask-Redis 扩展来设置远程地址 REDIS_URL,以下是一个简单的例子:
```python
from flask import Flask
from flask_redis import FlaskRedis
app = Flask(__name__)
app.config['REDIS_URL'] = 'redis://<redis_host>:<redis_port>/<redis_db>'
redis_store = FlaskRedis(app)
@app.route('/')
def index():
redis_store.set('key', 'value')
return 'Hello World!'
if __name__ == '__main__':
app.run()
```
在上面的例子中,我们首先设置了 REDIS_URL,然后使用 FlaskRedis 扩展创建了一个 redis_store 对象。在 index 路由中,我们使用 redis_store.set() 方法将一个键值对存储到 Redis 中。
阅读全文
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![7z](https://img-home.csdnimg.cn/images/20241231044736.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)