Guest User

Untitled

a guest
Oct 20th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. import time
  2.  
  3. import redis
  4. from flask import Flask
  5.  
  6. app = Flask(__name__)
  7. cache = redis.Redis(host='redis', port=6379)
  8.  
  9.  
  10. def get_hit_count():
  11. retries = 5
  12. while True:
  13. try:
  14. return cache.incr('hits')
  15. except redis.exceptions.ConnectionError as exc:
  16. if retries == 0:
  17. raise exc
  18. retries -= 1
  19. time.sleep(0.5)
  20.  
  21.  
  22. @app.route('/')
  23. def hello():
  24. count = get_hit_count()
  25. return 'Olá Mundo! Eu já fui visitado {} vezes.\n'.format(count)
  26.  
  27. if __name__ == "__main__":
  28. app.run(host="0.0.0.0", debug=True)
Add Comment
Please, Sign In to add comment