diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 1876023..5fb8768 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -50,9 +50,6 @@ jobs: pip install -r requirements.txt - name: Check FastAPI Server - env: - REDIS_HOST: localhost - REDIS_PORT: 6379 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 c6d9312..17c9e7c 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,13 @@ 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"), + port=int(os.getenv("REDIS_PORT", 6379)), + password=os.getenv("REDIS_PASSWORD", None), + db=0, + decode_responses=True + ) redis_client.ping() print("Connected to Redis successfully.") break