import time

import redis
from flask import Flask, Response

FLASK_PORT = 5000
REDIS_PORT = 6379

app = Flask(__name__)
cache = redis.Redis(host="redis", port=REDIS_PORT)

def get_hit_count():
    try:
        return cache.incr("hits")
    except redis.exceptions.ConnectionError as exc:
        return -1


@app.route("/")
def hello():
    return Response("Hello world! Server is running...", status=500, mimetype="text/plain")

@app.route("/count/")
def count():
    count = get_hit_count()

    if count == -1:
        return Response(f"Could not connect to Redis on Port {REDIS_PORT}", status=500, mimetype="text/plain")
    else:
        return Response(f"I have been called {count} times.")


if __name__ == "__main__":
      app.run(host="0.0.0.0", port=FLASK_PORT)
import time

import redis
from flask import Flask, Response

FLASK_PORT = 5000
REDIS_PORT = 6379

app = Flask(__name__)
cache = redis.Redis(host="redis", port=REDIS_PORT)

def get_hit_count():
    try:
        return cache.incr("hits")
    except redis.exceptions.ConnectionError as exc:
        return -1


@app.route("/")
def hello():
    return Response("Hello world! Server is running...", status=500, mimetype="text/plain")

@app.route("/count/")
def count():
    count = get_hit_count()

    if count == -1:
        return Response(f"Could not connect to Redis on Port {REDIS_PORT}", status=500, mimetype="text/plain")
    else:
        return Response(f"I have been called {count} times.")


if __name__ == "__main__":
      app.run(host="0.0.0.0", port=FLASK_PORT)