1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- package cache
- import (
- "github.com/druidcaesa/gotool"
- "log"
- "ulink-admin/modules/system/models/model"
- "ulink-admin/pkg/base"
- "ulink-admin/pkg/constant"
- )
- // GetRedisDictKey 根据key获取缓存中的字典数据
- func GetRedisDictKey(key string) []model.SysDictData {
- if exists, err := base.RedisDB.EXISTS(key); err != nil {
- log.Println("redis exists failed:", err)
- return nil
- } else if exists {
- get, err := base.RedisDB.GET(key)
- if err != nil {
- gotool.Logs.ErrorLog().Println(constant.RedisConstant{}.GetRedisError(), err.Error())
- return nil
- }
- list := model.SysDictData{}.UnmarshalDictList(get)
- return list
- }
- return nil
- }
- // SetRedisDict 保存字典数据
- func SetRedisDict(list []model.SysDictData) {
- dictList := model.SysDictData{}.MarshalDictList(list)
- base.RedisDB.SET(list[0].DictType, dictList)
- }
- // GetRedisConfigByKey 根据key从缓存中获取配置数据
- func GetRedisConfigByKey(key string) *model.SysConfig {
- if exists, err := base.RedisDB.EXISTS(key); err != nil {
- log.Println("redis exists failed:", err)
- return nil
- } else if exists {
- get, err := base.RedisDB.GET(key)
- if err != nil {
- gotool.Logs.ErrorLog().Println(constant.RedisConstant{}.GetRedisError(), err.Error())
- return nil
- }
- obj := model.SysConfig{}.UnmarshalDictObj(get)
- return obj
- }
- return nil
- }
- // SetRedisConfig 将配置存入缓存
- func SetRedisConfig(config *model.SysConfig) {
- s := model.SysConfig{}.MarshalDictObj(config)
- base.RedisDB.SET(config.ConfigKey, s)
- }
- // RemoveList 批量根据Key删除数据
- func RemoveList(list []string) {
- base.RedisDB.DELALL(list)
- }
- // SetDictCache 添加字典数据
- func SetDictCache(key string, value string) {
- base.RedisDB.SET(key, value)
- }
- // RemoveKey 根据key删除
- func RemoveKey(key string) int {
- del, err := base.RedisDB.DEL(key)
- if err != nil {
- gotool.Logs.ErrorLog().Println(err)
- }
- return del
- }
|