-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
41 lines (28 loc) · 833 Bytes
/
Copy pathapp.py
File metadata and controls
41 lines (28 loc) · 833 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import time
import os
import redis
from flask import Flask, render_template
app = Flask(__name__)
cache = redis.Redis(host='redis', port=6379, password=os.getenv('REDIS_PW'))
def get_hit_count():
retries = 5
while True:
try:
return cache.incr('hits')
except redis.exceptions.ConnectionError as exc:
if retries == 0:
#raise exc
return '4711 - no redis cache'
retries -= 1
time.sleep(0.5)
@app.route('/hello')
def hello():
count = get_hit_count()
return 'Hello World! I have been seen {} times.\n'.format(count)
@app.route('/')
def template():
count = get_hit_count()
#count = 1621
return render_template('index.html', count=count)
if __name__ == "__main__":
app.run(host="0.0.0.0", debug=True)