From d2b70e73ddfe1624a35bebdb6b8c7266f640aaa9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B1=9F=E4=B8=8D=E6=B1=9F?= <74400272+Seaver-Zhu@users.noreply.github.com> Date: Tue, 23 Jul 2024 14:00:31 +0800 Subject: [PATCH] fix redis no such key (#1647) ### What problem does this PR solve? fix Redis no such key #1614 ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) --------- Signed-off-by: seaver Co-authored-by: Kevin Hu --- api/apps/system_app.py | 6 +++--- rag/utils/redis_conn.py | 9 +++++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/api/apps/system_app.py b/api/apps/system_app.py index be276aca1..fddbe1427 100644 --- a/api/apps/system_app.py +++ b/api/apps/system_app.py @@ -59,9 +59,9 @@ def status(): st = timer() try: - qinfo = REDIS_CONN.health(SVR_QUEUE_NAME) - res["redis"] = {"status": "green", "elapsed": "{:.1f}".format((timer() - st)*1000.), - "pending": qinfo.get("pending", 0)} + if not REDIS_CONN.health(): + raise Exception("Lost connection!") + res["redis"] = {"status": "green", "elapsed": "{:.1f}".format((timer() - st)*1000.)} except Exception as e: res["redis"] = {"status": "red", "elapsed": "{:.1f}".format((timer() - st)*1000.), "error": str(e)} diff --git a/rag/utils/redis_conn.py b/rag/utils/redis_conn.py index 2ab670637..7d6dd4655 100644 --- a/rag/utils/redis_conn.py +++ b/rag/utils/redis_conn.py @@ -44,9 +44,14 @@ class RedisDB: logging.warning("Redis can't be connected.") return self.REDIS - def health(self, queue_name): + def health(self): + self.REDIS.ping() - return self.REDIS.xinfo_groups(queue_name)[0] + a, b = 'xx', 'yy' + self.REDIS.set(a, b, 3) + + if self.REDIS.get(a) == b: + return True def is_alive(self): return self.REDIS is not None