- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
Latest commit
24 lines (19 loc) · 517 Bytes
/
Copy pathapp.py
File metadata and controls
24 lines (19 loc) · 517 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
importtime
importredis
fromflaskimportFlask
app=Flask(__name__)
cache=redis.Redis(host='redis', port=6379)
defget_hit_count():
retries=5
whileTrue:
try:
returncache.incr('hits')
exceptredis.exceptions.ConnectionErrorasexc:
ifretries==0:
raiseexc
retries-=1
time.sleep(0.5)
@app.route('/')
defhello():
count=get_hit_count()
return'Hello Creator! I have been seen {} times.\n'.format(count)