From a04ebc2c5d6e60e23b3f2c6ed4e00500f443edfa Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Thu, 23 Nov 2023 11:55:18 -0500 Subject: [PATCH] feat: add redis test endpoint --- web.py | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/web.py b/web.py index 4bc8366..fc6fc0d 100644 --- a/web.py +++ b/web.py @@ -1,15 +1,14 @@ """ starts a web process """ +import os import random -from cowsay import cowsay -from cowsay import get_random_cow -from flask import Flask -from flask import redirect +import redis +from flask import Flask, redirect -from shared import consume_cpu -from shared import consume_memory +from cowsay import cowsay, get_random_cow +from shared import consume_cpu, consume_memory app = Flask(__name__) @@ -46,5 +45,22 @@ def index(path): return html, status_code +@app.route("/redis") +def redis_path(): + """ + tests redis + """ + + host = os.getenv("REDIS_HOST") + port = int(os.getenv("REDIS_PORT")) + password = os.getenv("REDIS_PASS") + connection = redis.Redis( + host=host, port=port, password=password, decode_responses=True + ) + connection.set("foo", "bar") + html = f"
{connection.get('foo')}
" + return html, 200 + + if __name__ == "__main__": app.run()