Files
mayfly-go/server/pkg/cache/str_cache.go
2022-12-26 20:53:07 +08:00

35 lines
669 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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)
}
}