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
43 lines
908 B
package cache
|
|
|
|
import (
|
|
"encoding/json"
|
|
"recook/internal/dbc"
|
|
"recook/internal/service/comFunc"
|
|
"strconv"
|
|
"time"
|
|
)
|
|
|
|
const TmpTime = 60
|
|
const TmpUserData = "MyInfo_"
|
|
const (
|
|
TmpSelfType = TmpUserData + "Self_"
|
|
TmpShareType = TmpUserData + "Share_"
|
|
TmpTeamType = TmpUserData + "Team_"
|
|
)
|
|
|
|
func SetTmpData(userId uint, tmpType string, data interface{}) {
|
|
var tmpData, err = json.Marshal(data)
|
|
if err != nil {
|
|
comFunc.PrintErr("setTmpData json error:", err)
|
|
return
|
|
}
|
|
|
|
_, err = dbc.Rds.Set(tmpType+strconv.Itoa(int(userId)), tmpData, TmpTime*time.Second).Result()
|
|
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
|
|
}
|