Skip to content

Commit

Permalink
feat: 稿件推送时同时创建hash表
Browse files Browse the repository at this point in the history
  • Loading branch information
RockChinQ committed Apr 27, 2024
1 parent a6b019b commit 31e97be
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions backend/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func SetDefault() {

// 服务token
viper.SetDefault("service.token", "campux")
viper.SetDefault("service.bots", []int64{123456789})

// 数据库
viper.SetDefault("database.mongo.uri", "mongodb://localhost:27017")
Expand Down
25 changes: 24 additions & 1 deletion backend/mq/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package mq

import (
"context"
"strconv"

"github.com/redis/go-redis/v9"
"github.com/spf13/viper"
Expand Down Expand Up @@ -38,7 +39,29 @@ func (r *RedisStreamMQ) PublishPost(postID int) error {
"post_id": postID,
},
}).Result()
return err

if err != nil {
return err
}

// 创建散列表跟踪发布状态 HSET publish_post_status:post_id campuxbot_1234567 0 campuxbot_1234568 0
var bots []int64

err = viper.UnmarshalKey("service.bots", &bots)

if err != nil {
return err
}

for _, bot := range bots {
err = r.Client.HSet(context.Background(), "publish_post_status:"+strconv.Itoa(postID), "campuxbot_"+strconv.FormatInt(bot, 10), 0).Err()

if err != nil {
return err
}
}

return nil
}

func (r *RedisStreamMQ) NewPost(postID int) error {
Expand Down

0 comments on commit 31e97be

Please sign in to comment.