You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.1 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package cache
import (
"errors"
"recook/internal/dbc"
"recook/internal/model/newertehui"
"strconv"
)
const TeHuiCacheKey = "NewerTehuiGoodsID"
var EmptyError = errors.New("The newertehui table is empty\n")
// FlushNewerGoodsID 将特惠的good id放入缓存形成集合 然后在查找的时候可以快速查找,减少数据库负担
func FlushNewerGoodsID() error {
// 先删除,后添加,每次都刷新
DelNewerTehuiSet()
var newerGoods []struct {
GoodsId uint `gorm:"goods_id" json:"goodsId"`
}
dbc.DB.Model(&newertehui.Goods{}).Select("goods_id").Scan(&newerGoods)
if len(newerGoods) < 1 {
return EmptyError
}
var ids []string
for _, newerGood := range newerGoods {
ids = append(ids, strconv.Itoa(int(newerGood.GoodsId)))
}
if _, err := dbc.Rds.SAdd(TeHuiCacheKey, ids).Result(); err != nil {
return err
}
return nil
}
func IsMemberOfNewerTehui(id string) (isMember bool, err error) {
isMember, err = dbc.Rds.SIsMember(TeHuiCacheKey, id).Result()
return
}
// DelNewerTehuiSet 删除集合
func DelNewerTehuiSet() (int64, error) {
return dbc.Rds.Del(TeHuiCacheKey).Result()
}