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.

43 lines
908 B

4 years ago
package cache
import (
"encoding/json"
"recook/internal/dbc"
"recook/internal/service/comFunc"
"strconv"
"time"
)
4 years ago
const TmpTime = 60
const TmpUserData = "MyInfo_"
4 years ago
const (
4 years ago
TmpSelfType = TmpUserData + "Self_"
TmpShareType = TmpUserData + "Share_"
TmpTeamType = TmpUserData + "Team_"
4 years ago
)
func SetTmpData(userId uint, tmpType string, data interface{}) {
var tmpData, err = json.Marshal(data)
if err != nil {
comFunc.PrintErr("setTmpData json error:", err)
return
}
4 years ago
_, err = dbc.Rds.Set(tmpType+strconv.Itoa(int(userId)), tmpData, TmpTime*time.Second).Result()
4 years ago
if err != nil {
comFunc.PrintErr("setTmpData set error:", err)
}
return
}
func GetTmpData(userId uint, tmpType string) (res string, ok bool) {
res, err := dbc.Rds.Get(tmpType + strconv.Itoa(int(userId))).Result()
if err != nil {
comFunc.PrintErr("setTmpData set error:", err)
ok = false
return
}
ok = true
return
}