mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-11-04 00:10:25 +08:00
feat: 支持redis缓存权限等信息
This commit is contained in:
34
server/pkg/cache/str_cache.go
vendored
Normal file
34
server/pkg/cache/str_cache.go
vendored
Normal 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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user