from redis_client import get_client
+import redis
from flask import Flask, Response, request
def stats():
redis_client.increment_hits("stats")
try:
- stats = redis_client.get_stats()
- return {"stats": [{stat[0]: stat[1]} for stat in stats][::-1]}
+ stats = sorted(
+ [stat for stat in redis_client.get_stats()], key=lambda stat: -stat[1]
+ )
+ return {"stats": [{stat[0]: stat[1]} for stat in stats]}
except redis.exceptions.ConnectionError as e:
app.logger.exception(e)
return Response("Internal Server Error", 500)
def get_stats(self) -> list[tuple]:
"""Returns stats values from a Redis sorted set as a tuple of key-value pairs."""
- stats = self.r.zscan_iter("hits")
+ stats = self.r.zscan_iter("hits", score_cast_func=int)
if stats is None:
logger.debug("Uninitialized stats object")
return []