- 新增 aqi.csv 文件,包含 2020 年 1 月 1 日至 9 月 27 日的空气质量数据- 数据包括日期、AQI、质量等级以及 PM2.5、PM10、SO2、CO、NO2、O3等污染物含量
28 lines
672 B
Python
28 lines
672 B
Python
import time
|
||
from flask import Flask
|
||
import redis
|
||
|
||
app = Flask(__name__)
|
||
|
||
# 使用服务名 "redis" 作为 host,docker-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) |