Skip to content

Instantly share code, notes, and snippets.

@kudaliar032
Created December 14, 2019 06:27
Show Gist options
  • Save kudaliar032/6298d3fdbb374218dc94ea5afad96046 to your computer and use it in GitHub Desktop.
Save kudaliar032/6298d3fdbb374218dc94ea5afad96046 to your computer and use it in GitHub Desktop.
app.py tefa-14-dec
import time
import redis
from flask import Flask
app = Flask(__name__)
cache = redis.Redis(host='redis', port=6379)
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 'Hello World! Saya sudah terlihat {} kali.\n'.format(count)
if __name__ == "__main__":
app.run(host="0.0.0.0", debug=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment