From ef37b5d242008c6f334661ab115b7d0c010a880b Mon Sep 17 00:00:00 2001 From: RockChinQ <1010553892@qq.com> Date: Tue, 23 Jul 2024 14:26:44 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=85=81=E8=AE=B8=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89hash=E8=A1=A8=E5=90=8D=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.example | 1 + campux/mq/redis.py | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/.env.example b/.env.example index 0af291b..f73e147 100644 --- a/.env.example +++ b/.env.example @@ -11,6 +11,7 @@ CAMPUX_REDIS_PASSWORD="" CAMPUX_REDIS_PUBLISH_POST_STREAM="campux_publish_post" CAMPUX_REDIS_NEW_POST_STREAM="campux_new_post" CAMPUX_REDIS_POST_CANCEL_STREAM="campux_post_cancel" +CAMPUX_REDIS_POST_PUBLISH_STATUS_HASH="campux_post_publish_status" CAMPUX_HELP_MESSAGE="填写未匹配指令时的帮助信息。每用户每60秒只会响应一次。" CAMPUX_REVIEW_HELP_MESSAGE="填写未匹配指令时的审核帮助信息" CAMPUX_REVIEW_QQ_GROUP_ID=123456789 diff --git a/campux/mq/redis.py b/campux/mq/redis.py index e29e468..da4bc22 100644 --- a/campux/mq/redis.py +++ b/campux/mq/redis.py @@ -15,6 +15,9 @@ 'campux_redis_post_cancel_stream': 'campux_post_cancel', } +hash_table_name = { + 'campux_redis_post_publish_status_hash': 'campux_post_publish_status' +} class RedisStreamMQ: @@ -44,7 +47,13 @@ async def initialize(self): if hasattr(self.ap.config, stream_key): streams_name[stream_key] = getattr(self.ap.config, stream_key) + # 从config取出hash table的名称 + for hash_table_key in hash_table_name.keys(): + if hasattr(self.ap.config, hash_table_key): + hash_table_name[hash_table_key] = getattr(self.ap.config, hash_table_key) + logger.info(f"Redis Streams: {streams_name}") + logger.info(f"Redis Hash Tables: {hash_table_name}") # 创建xgroup # 检查是否存在同名group @@ -162,7 +171,7 @@ async def check_new_post(self, message: tuple): async def mark_post_published(self, post_id): await self.redis_client.hset( - f"publish_post_status:{post_id}", + f"{hash_table_name['campux_redis_post_publish_status_hash']}{post_id}", self.get_instance_identity(), 1 )