diff --git a/backend/config/config.go b/backend/config/config.go index 7e4c192..02b5e17 100644 --- a/backend/config/config.go +++ b/backend/config/config.go @@ -37,6 +37,7 @@ func SetDefault() { viper.SetDefault("mq.redis.stream.publish_post", "campux_publish_post") viper.SetDefault("mq.redis.stream.new_post", "campux_new_post") viper.SetDefault("mq.redis.stream.post_cancel", "campux_post_cancel") + viper.SetDefault("mq.redis.hash.post_publish_status", "campux_post_publish_status") } diff --git a/backend/mq/redis.go b/backend/mq/redis.go index 2f1a5ca..a5f2929 100644 --- a/backend/mq/redis.go +++ b/backend/mq/redis.go @@ -47,7 +47,7 @@ func (r *RedisStreamMQ) PublishPost(postID int) error { return err } - // 创建散列表跟踪发布状态 HSET publish_post_status:post_id campuxbot_1234567 0 campuxbot_1234568 0 + // 创建散列表跟踪发布状态 HSET {{ viper.GetString("mq.redis.hash.post_publish_status") }}post_id campuxbot_1234567 0 campuxbot_1234568 0 var bots []int64 err = viper.UnmarshalKey("service.bots", &bots) @@ -57,7 +57,7 @@ func (r *RedisStreamMQ) PublishPost(postID int) error { } for _, bot := range bots { - err = r.Client.HSet(context.Background(), "publish_post_status:"+strconv.Itoa(postID), "campuxbot_"+strconv.FormatInt(bot, 10), 0).Err() + err = r.Client.HSet(context.Background(), viper.GetString("mq.redis.hash.post_publish_status")+strconv.Itoa(postID), "campuxbot_"+strconv.FormatInt(bot, 10), 0).Err() if err != nil { return err @@ -88,8 +88,8 @@ func (r *RedisStreamMQ) PostCancel(postID int) error { } func (r *RedisStreamMQ) CheckPostPublishStatus(postID int) (bool, error) { - // HGETALL publish_post_status:77 - status, err := r.Client.HGetAll(context.Background(), "publish_post_status:"+strconv.Itoa(postID)).Result() + // HGETALL {{ viper.GetString("mq.redis.hash.post_publish_status") }}77 + status, err := r.Client.HGetAll(context.Background(), viper.GetString("mq.redis.hash.post_publish_status")+strconv.Itoa(postID)).Result() if err != nil { return false, err @@ -106,6 +106,6 @@ func (r *RedisStreamMQ) CheckPostPublishStatus(postID int) (bool, error) { // 删除稿件发布跟踪hash表 func (r *RedisStreamMQ) DeletePostPublishStatus(postID int) error { - _, err := r.Client.Del(context.Background(), "publish_post_status:"+strconv.Itoa(postID)).Result() + _, err := r.Client.Del(context.Background(), viper.GetString("mq.redis.hash.post_publish_status")+strconv.Itoa(postID)).Result() return err } diff --git a/backend/service/routine/confirm_posted.go b/backend/service/routine/confirm_posted.go index a28bab7..772ed5b 100644 --- a/backend/service/routine/confirm_posted.go +++ b/backend/service/routine/confirm_posted.go @@ -10,7 +10,7 @@ import ( func ConfirmPosted(db database.MongoDBManager, msq mq.RedisStreamMQ) { // 取出状态为“队列中”的稿件 - // 检查消息队列中HGETALL publish_post_status:post_id 的所有值是否都是1 + // 检查消息队列中HGETALL {{ viper.GetString("mq.redis.hash.post_publish_status") }}post_id 的所有值是否都是1 // 如果是, 则更新稿件状态为“已发布” inQueuePosts, _, err := db.GetPosts(-1, database.POST_STATUS_IN_QUEUE, 1, 1, 100) if err != nil { diff --git a/main.go b/main.go index 9c5364d..a7a4f51 100644 --- a/main.go +++ b/main.go @@ -23,7 +23,7 @@ func main() { } if created { - panic("请修改配置文件") + panic("请修改配置文件后重启") } // 启动服务