You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

20 lines
505 B
Python

from flask import Flask
from redis import ConnectionPool, Redis
app = Flask(__name__)
# 创建 Redis 连接池
pool = ConnectionPool(host='localhost', port=6379, db=0)
# 创建 Redis 客户端
redis_client = Redis(connection_pool=pool)
@app.route('/')
def hello():
# 从连接池中获取 Redis 连接
conn = redis_client.connection_pool.get_connection()
# 使用 Redis 连接进行操作
result = conn.get('key')
# 将连接归还到连接池中
conn.close()
return result