from flask import Blueprint, request, jsonify from ZhuQue.Redis.redis_client import get_redis_connection from ZhuQue.Db.db import execute_query # 注册蓝图 blog_blueprint = Blueprint('blog', __name__) # http://127.0.0.1:5000/ZhuQue/blog/sql @blog_blueprint.route('/sql', methods=['GET']) def sql(): # 从请求中获取 'id' 参数 id = request.args.get('id', type=int) if id is None: return jsonify({'error': 'Missing ID'}), 400 # 查询sql sql = 'select * from a where id= %s' res = execute_query(sql, (id,), one=True) # 如果没有查询结果 if res is None: return jsonify({'error': 'Error ID'}), 400 return res # http://127.0.0.1:5000/ZhuQue/blog/redis @blog_blueprint.route('/redis', methods=['GET']) def redis(): # 测试 Redis 连接 redis_connection = get_redis_connection() redis_connection.set('foo', 'bar') value = redis_connection.get('foo') if value: print('foo:', value.decode("utf-8")) return value.decode("utf-8") else : return jsonify({'error': 'Error ID'}), 400