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.
|
|
|
|
package cache
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"errors"
|
|
|
|
|
"recook/internal/dbc"
|
|
|
|
|
"recook/internal/model/newertehui"
|
|
|
|
|
"strconv"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const TeHuiCacheKey = "NewerTehuiGoodsID"
|
|
|
|
|
|
|
|
|
|
var EmptyError = errors.New("The newertehui table is empty")
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 删除集合
|
|
|
|
|
func DelNewerTehuiSet() (int64, error) {
|
|
|
|
|
return dbc.Rds.Del(TeHuiCacheKey).Result()
|
|
|
|
|
}
|