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.
108 lines
2.0 KiB
108 lines
2.0 KiB
package cache
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/go-redis/redis"
|
|
"recook/internal/dbc"
|
|
"time"
|
|
)
|
|
|
|
// @Style 设置管理员登录token
|
|
func SetAdminLoginCache(uid uint, token string) {
|
|
key := fmt.Sprintf("manage_%d", uid)
|
|
err := dbc.Rds.Set(key, token, time.Hour*12).Err()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// @Style 获取管理员登录token
|
|
func GetAdminLoginCache(id uint) string {
|
|
k := fmt.Sprintf("manage_%d", id)
|
|
val, err := dbc.Rds.Get(k).Result()
|
|
|
|
if err != nil {
|
|
if err == redis.Nil {
|
|
return ""
|
|
} else {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
return val
|
|
}
|
|
|
|
// @Style 退出登录
|
|
func RemoveAdminLoginCache(id uint) {
|
|
key := fmt.Sprintf("manage_%d", id)
|
|
dbc.Rds.Del(key)
|
|
}
|
|
|
|
// @Style 设置供应商登录token
|
|
func SetGysLoginCache(uid uint, token string) {
|
|
key := fmt.Sprintf("manage_gys_%d", uid)
|
|
err := dbc.Rds.Set(key, token, time.Hour*12).Err()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// @Style 获取供应商登录token
|
|
func GetGysLoginCache(id uint) string {
|
|
k := fmt.Sprintf("manage_gys_%d", id)
|
|
val, err := dbc.Rds.Get(k).Result()
|
|
|
|
if err != nil {
|
|
if err == redis.Nil {
|
|
return ""
|
|
} else {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
return val
|
|
}
|
|
|
|
// @Style 供应商退出登录
|
|
func RemoveGysLoginCache(id uint) {
|
|
key := fmt.Sprintf("manage_gys_%d", id)
|
|
dbc.Rds.Del(key)
|
|
}
|
|
|
|
// @Style app登录缓存
|
|
func SetUserLoginCache(id uint, token string, deviceType int) {
|
|
k := fmt.Sprintf("login:%d:user_%d", deviceType, id)
|
|
err := dbc.Rds.Set(k, token, 0).Err()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
// @Style 获取app登录缓存
|
|
func GetUserLoginCache(id uint, deviceType int) string {
|
|
k := fmt.Sprintf("login:%d:user_%d", deviceType, id)
|
|
val, err := dbc.Rds.Get(k).Result()
|
|
if err != nil {
|
|
if err == redis.Nil {
|
|
return ""
|
|
} else {
|
|
panic(err)
|
|
}
|
|
}
|
|
return val
|
|
}
|
|
|
|
// @Style 获取app登录缓存
|
|
func GetxxxCache(id uint, deviceType int) string {
|
|
k := fmt.Sprintf("login:%d:user_%d", deviceType, id)
|
|
val, err := dbc.Rds.Get(k).Result()
|
|
if err != nil {
|
|
if err == redis.Nil {
|
|
return ""
|
|
} else {
|
|
panic(err)
|
|
}
|
|
}
|
|
return val
|
|
}
|