From 49a01c65528c19e2acea8ed27971987bc7393963 Mon Sep 17 00:00:00 2001 From: coders007 <22373362@buaa.edu.cn> Date: Sun, 27 Apr 2025 11:20:58 +0800 Subject: [PATCH 1/7] [fix]:fix redis config in redis.py --- app/utils/redis.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/utils/redis.py b/app/utils/redis.py index c6d9312..387d895 100644 --- a/app/utils/redis.py +++ b/app/utils/redis.py @@ -1,5 +1,6 @@ import redis import time +import os redis_client = None # 全局 Redis 客户端变量 @@ -13,7 +14,16 @@ def get_redis_client(): while True: try: print("Connecting to Redis...") - redis_client = redis.StrictRedis(host='localhost', port=6379, db=0, decode_responses=True) + redis_client = redis.StrictRedis( + # host=os.getenv("REDIS_HOST", "localhost"), # 从环境变量读取 Redis 主机名 + # port=int(os.getenv("REDIS_PORT", 6379)), # 从环境变量读取 Redis 端口 + # password=os.getenv("REDIS_PASSWORD", None), # 从环境变量读取 Redis 密码 + host='redis', + port=6379, + password='OKredis', + db=0, + decode_responses=True + ) redis_client.ping() print("Connected to Redis successfully.") break From a14e2396da91f4865ab01b7850c96c2739bbfd4a Mon Sep 17 00:00:00 2001 From: coders007 <22373362@buaa.edu.cn> Date: Sun, 27 Apr 2025 11:39:47 +0800 Subject: [PATCH 2/7] [fix]:fix check.yml(pytest and redis config) --- .github/workflows/check.yml | 5 +++++ app/utils/redis.py | 9 +++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 1876023..91291ef 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -49,10 +49,15 @@ jobs: python -m pip install --upgrade pip pip install -r requirements.txt + - name: Run tests + run: pytest --maxfail=1 --disable-warnings -q + - name: Check FastAPI Server env: REDIS_HOST: localhost REDIS_PORT: 6379 + REDIS_PASSWORD: OKredis + REDIS_DB: 0 run: | uvicorn app.main:app --host 0.0.0.0 --port 8000 --log-level warning & sleep 5 diff --git a/app/utils/redis.py b/app/utils/redis.py index 387d895..17c9e7c 100644 --- a/app/utils/redis.py +++ b/app/utils/redis.py @@ -15,12 +15,9 @@ def get_redis_client(): try: print("Connecting to Redis...") redis_client = redis.StrictRedis( - # host=os.getenv("REDIS_HOST", "localhost"), # 从环境变量读取 Redis 主机名 - # port=int(os.getenv("REDIS_PORT", 6379)), # 从环境变量读取 Redis 端口 - # password=os.getenv("REDIS_PASSWORD", None), # 从环境变量读取 Redis 密码 - host='redis', - port=6379, - password='OKredis', + host=os.getenv("REDIS_HOST", "localhost"), + port=int(os.getenv("REDIS_PORT", 6379)), + password=os.getenv("REDIS_PASSWORD", None), db=0, decode_responses=True ) From 15456b5afb51c7afdb910327732c42ba7069b655 Mon Sep 17 00:00:00 2001 From: coders007 <22373362@buaa.edu.cn> Date: Sun, 27 Apr 2025 11:47:08 +0800 Subject: [PATCH 3/7] [fix]:fix check.yml --- .github/workflows/check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 91291ef..d94dd71 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -50,7 +50,7 @@ jobs: pip install -r requirements.txt - name: Run tests - run: pytest --maxfail=1 --disable-warnings -q + run: pytest - name: Check FastAPI Server env: From 8525ac2372e614949fc19bd259f1ee78e36103be Mon Sep 17 00:00:00 2001 From: coders007 <22373362@buaa.edu.cn> Date: Sun, 27 Apr 2025 11:50:37 +0800 Subject: [PATCH 4/7] [fix]:fix check.yml --- .github/workflows/check.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index d94dd71..ed00a97 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -49,8 +49,8 @@ jobs: python -m pip install --upgrade pip pip install -r requirements.txt - - name: Run tests - run: pytest + # - name: Run tests + # run: pytest - name: Check FastAPI Server env: From b324fe8225c98e916b05015d19affd301a92ad55 Mon Sep 17 00:00:00 2001 From: coders007 <22373362@buaa.edu.cn> Date: Sun, 27 Apr 2025 11:54:13 +0800 Subject: [PATCH 5/7] [fix]:what the hell --- .github/workflows/check.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index ed00a97..d94dd71 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -49,8 +49,8 @@ jobs: python -m pip install --upgrade pip pip install -r requirements.txt - # - name: Run tests - # run: pytest + - name: Run tests + run: pytest - name: Check FastAPI Server env: From f6d793cf7729f2827eaa82962a8c1f0083a1ff0a Mon Sep 17 00:00:00 2001 From: coders007 <22373362@buaa.edu.cn> Date: Sun, 27 Apr 2025 19:43:27 +0800 Subject: [PATCH 6/7] [fix]:cancel pytest --- .github/workflows/check.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index d94dd71..e2e440c 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -49,9 +49,6 @@ jobs: python -m pip install --upgrade pip pip install -r requirements.txt - - name: Run tests - run: pytest - - name: Check FastAPI Server env: REDIS_HOST: localhost From 0b958b9a2cc396e34249462ef33388a3524d6e57 Mon Sep 17 00:00:00 2001 From: coders007 <22373362@buaa.edu.cn> Date: Sun, 27 Apr 2025 19:48:13 +0800 Subject: [PATCH 7/7] [fix]:try to fix connection --- .github/workflows/check.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index e2e440c..5fb8768 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -50,11 +50,6 @@ jobs: pip install -r requirements.txt - name: Check FastAPI Server - env: - REDIS_HOST: localhost - REDIS_PORT: 6379 - REDIS_PASSWORD: OKredis - REDIS_DB: 0 run: | uvicorn app.main:app --host 0.0.0.0 --port 8000 --log-level warning & sleep 5