1 Star 0 Fork 0

is小强/beego-tool

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
redis_cache.go 889 Bytes
一键复制 编辑 原始数据 按行查看 历史
is小强 提交于 12个月前 . 修正redis cache实例化
/**
* Created by goland.
* User: adam_wang
* Date: 2023-08-01 00:10:27
*/
package database
import (
"fmt"
"github.com/beego/beego/v2/client/cache"
_ "github.com/beego/beego/v2/client/cache/redis"
beego "github.com/beego/beego/v2/server/web"
)
var RedisCache cache.Cache
func init() {
redisHost, _ := beego.AppConfig.String("redis::address")
port, _ := beego.AppConfig.String("redis::port")
dataBase, _ := beego.AppConfig.String("redis::cache_database")
password, _ := beego.AppConfig.String("redis::password")
redisKey, _ := beego.AppConfig.String("redis::cache_key")
config := fmt.Sprintf(`{"key":"%s","conn":"%s@%s:%s","dbNum":"%s"}`, redisKey, password, redisHost, port, dataBase)
var err error
RedisCache, err = cache.NewCache("redis", config)
if err != nil || RedisCache == nil {
fmt.Println(err)
errMsg := "failed to init redis cache"
panic(errMsg)
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/adam-qiang/beego-tool.git
git@gitee.com:adam-qiang/beego-tool.git
adam-qiang
beego-tool
beego-tool
v1.2.1

搜索帮助