@@ -0,0 +1,85 @@
|
||||
package vidmod
|
||||
|
||||
import (
|
||||
"91porn-server/app/appg"
|
||||
"91porn-server/common/constant/redisconst"
|
||||
"91porn-server/common/log"
|
||||
"91porn-server/common/redis"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/vmihailenco/msgpack/v5"
|
||||
)
|
||||
|
||||
func getRedis() *redis.Client {
|
||||
return appg.Redis
|
||||
}
|
||||
|
||||
// GetByIDFromRedis 根据id获取一条记录
|
||||
func GetByIDFromRedis(id string) (vid VideoModel, err error) {
|
||||
redisKey := redisconst.DataCachKey(table, id)
|
||||
redisc := getRedis()
|
||||
if redisc == nil || !redisc.Exists(redisKey) {
|
||||
vid, err = GetVideoInfo(id)
|
||||
if err != nil {
|
||||
log.Warn(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "GetByID", table, "FindOne", err), log.Any("id", id))
|
||||
}
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if redisc == nil {
|
||||
return
|
||||
}
|
||||
var jsonBytes []byte
|
||||
jsonBytes, err = msgpack.Marshal(&vid)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = redisc.Set(redisKey, string(jsonBytes), redisconst.DataCachExpire)
|
||||
return
|
||||
}
|
||||
str, err := redisc.Get(redisKey)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if str == nil {
|
||||
err = errors.New("redis key is null")
|
||||
return
|
||||
}
|
||||
err = msgpack.Unmarshal([]byte(*str), &vid)
|
||||
if err != nil {
|
||||
log.Warn(fmt.Sprintf("[METHOD-%s]==> Model %s %s fail error:%+v:", "GetByID", table, "FindOne", err), log.Any("id", id))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func GetShareListFromRedis() ([]ShareInfo, error) {
|
||||
redisKey := redisconst.GetVideoShareListKey()
|
||||
redisc := getRedis()
|
||||
if redisc == nil || !redisc.Exists(redisKey) {
|
||||
status := CheckPass
|
||||
sis, err := getShareList(&status)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if redisc == nil {
|
||||
return sis, err
|
||||
}
|
||||
var jsonBytes []byte
|
||||
jsonBytes, err = msgpack.Marshal(sis)
|
||||
if err != nil {
|
||||
return sis, nil
|
||||
}
|
||||
err = redisc.Set(redisKey, jsonBytes, redisconst.GetVideoShareListExpired())
|
||||
return sis, nil
|
||||
}
|
||||
str, err := redisc.Get(redisKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if str == nil {
|
||||
return nil, errors.New("redis key is null")
|
||||
}
|
||||
var sis []ShareInfo
|
||||
return sis, msgpack.Unmarshal([]byte(*str), &sis)
|
||||
}
|
||||
Reference in New Issue
Block a user