feat: 支持redis缓存权限等信息

This commit is contained in:
meilin.huang
2022-12-26 20:53:07 +08:00
parent 4fec38724d
commit 4a26bb3ba5
11 changed files with 200 additions and 86 deletions

34
server/pkg/cache/str_cache.go vendored Normal file
View File

@@ -0,0 +1,34 @@
package cache
import "mayfly-go/pkg/rediscli"
var strCache map[string]string
// 如果系统有设置redis信息则从redis获取否则本机内存获取
func GetStr(key string) string {
if rediscli.GetCli() == nil {
checkStrCache()
return strCache[key]
}
res, err := rediscli.Get(key)
if err != nil {
return ""
}
return res
}
// 如果系统有设置redis信息则使用redis存否则存于本机内存
func SetStr(key, value string) {
if rediscli.GetCli() == nil {
checkStrCache()
strCache[key] = value
return
}
rediscli.Set(key, value, 0)
}
func checkStrCache() {
if strCache == nil {
strCache = make(map[string]string)
}
}