Skip to content

Commit

Permalink
feat: 允许自定义hash表名称
Browse files Browse the repository at this point in the history
  • Loading branch information
RockChinQ committed Jul 23, 2024
1 parent 049d01e commit ef37b5d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion campux/mq/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
)
Expand Down

0 comments on commit ef37b5d

Please sign in to comment.