From 27407443b9039e2ee03b3e2108de55de3b393218 Mon Sep 17 00:00:00 2001 From: Jacob Date: Sun, 7 Sep 2025 15:22:25 -0500 Subject: [PATCH] Replace zscan_iter with zrevrange --- app.py | 4 +--- redis_client.py | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/app.py b/app.py index 190e884..d3eb003 100644 --- a/app.py +++ b/app.py @@ -22,9 +22,7 @@ def create_app(): def stats(): redis_client.increment_hits("stats") try: - stats = sorted( - [stat for stat in redis_client.get_stats()], key=lambda stat: -stat[1] - ) + stats = redis_client.get_stats() return {"stats": [{stat[0]: stat[1]} for stat in stats]} except redis.exceptions.ConnectionError as e: app.logger.exception(e) diff --git a/redis_client.py b/redis_client.py index cb366ea..19b2d99 100644 --- a/redis_client.py +++ b/redis_client.py @@ -23,7 +23,7 @@ class RedisClient: 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", score_cast_func=int) + stats = self.r.zrevrange("hits", 0, -1, withscores=True, score_cast_func=int) if stats is None: logger.debug("Uninitialized stats object") return [] -- 2.30.2