-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
27 lines (24 loc) · 707 Bytes
/
app.py
File metadata and controls
27 lines (24 loc) · 707 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
import time
import os
import redis
from flask import Flask
hostname=os.getenv('REDIS_HOSTNAME')
password=os.getenv('REDIS_PASSWORD')
port=os.getenv('REDIS_PORT')
# host='localhost',port=6379,db=0,password='Prabhat'
app = Flask(__name__)
cache = redis.Redis(host=hostname,port=port,password=password)
def get_hit_count():
retries = 5
while True:
try:
return cache.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 '<h2> Hello World! We have been seen {} times.\n <h2>'.format(count)