dev_xulongjin b4ef64314b feat(商务大数据分析): 五一前作业更新
- 新增 aqi.csv 文件,包含 2020 年 1 月 1 日至 9 月 27 日的空气质量数据- 数据包括日期、AQI、质量等级以及 PM2.5、PM10、SO2、CO、NO2、O3等污染物含量
2025-05-06 20:31:09 +08:00

28 lines
672 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import time
from flask import Flask
import redis
app = Flask(__name__)
# 使用服务名 "redis" 作为 hostdocker-compose 会自动识别
def get_redis_client():
return redis.Redis(host='hadoop102', port=6379)
def get_hit_count():
retries = 5
while True:
try:
return get_redis_client().incr('hits')
except redis.exceptions.ConnectionError as exc:
if retries == 0:
raise exc
retries -= 1
time.sleep(0.5)
@app.route('/')
def hello():
count = get_hit_count()
return f'Hello World! I have been seen {count} times.\n'
if __name__ == '__main__':
app.run(debug=True)