package async import ( "blog/internal/consts" "blog/internal/model/blog" "blog/third_party/database" "context" "math" "github.com/redis/go-redis/v9" ) var diaryChannel chan string func init() { f := math.Pow(2, 5) diaryChannel = make(chan string, int(f)) go func() { ctx := context.Background() for id := range diaryChannel { // log.Println(id) var diary blog.BlogDiary database.GormTemplate.Table("blog_diaries").Where("id = ?", id).First(&diary) database.RedisTemplate.ZAdd(ctx, consts.REDIS_BLOG_DIARY_LATEST, redis.Z{Score: float64(diary.PublishTime), Member: diary}) } }() } func PublishDiary(id string) { diaryChannel <- id }