From 9d75cc250d08b2f1a560ca7ffdf635c2140124e3 Mon Sep 17 00:00:00 2001 From: aaron <> Date: Thu, 6 Mar 2025 17:58:36 +0800 Subject: [PATCH] update --- app/api/endpoints/order.py | 4 ++-- app/core/redis_client.py | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/api/endpoints/order.py b/app/api/endpoints/order.py index 6b30bc3..57821f0 100644 --- a/app/api/endpoints/order.py +++ b/app/api/endpoints/order.py @@ -348,7 +348,7 @@ async def create_order( # 添加到新订单队列 if db_order.address_community_id: background_tasks.add_task( - redis_client.push_order_to_queue, + redis_client.push_new_order_to_queue, db_order.address_community_id, db_order.orderid, db @@ -1461,7 +1461,7 @@ async def deliveryman_check_new_orders( """检查新订单""" # 从Redis获取新订单ID列表 - order_ids = redis_client.pop_orders_from_queue(deliveryman.userid, deliveryman.community_id, 10) + order_ids = redis_client.pop_new_orders_from_queue(deliveryman.userid) if not order_ids: return success_response(data={ diff --git a/app/core/redis_client.py b/app/core/redis_client.py index d437222..58c5646 100644 --- a/app/core/redis_client.py +++ b/app/core/redis_client.py @@ -67,7 +67,7 @@ class RedisClient: logging.error(f"获取今日队列中的订单数量失败: {str(e)}") return 0 - def push_order_to_queue(self, community_id: int, order_id: str, db: Session) -> bool: + def push_new_order_to_queue(self, community_id: int, order_id: str, db: Session) -> bool: """ 添加新订单到社区队列 @@ -81,9 +81,9 @@ class RedisClient: """ try: # 查询所有社区的用户 - users = db.query(UserDB).filter(UserDB.community_id == community_id, UserDB.roles == UserRole.DELIVERYMAN).all() + users = db.query(UserDB).filter(UserDB.community_id == community_id).all() for user in users: - key = f"user:{user.userid}:community:{community_id}:new_orders" + key = f"deliveryman:{user.userid}:new_orders" # 使用 LPUSH 将订单ID添加到列表头部 self.client.lpush(key, order_id) # 设置过期时间为24小时 @@ -93,7 +93,7 @@ class RedisClient: logging.error(f"添加新订单到队列失败: {str(e)}") return False - def pop_orders_from_queue(self, user_id: int, community_id: int, count: int = 10) -> List[str]: + def pop_new_orders_from_queue(self, user_id: int, count: int = 10) -> List[str]: """ 获取社区新订单列表 @@ -106,7 +106,7 @@ class RedisClient: List[str]: 订单ID列表 """ try: - key = f"user:{user_id}:community:{community_id}:new_orders" + key = f"deliveryman:{user_id}:new_orders" # 获取订单列表, orders = self.client.lpop(key, count) return orders