mirror of
https://github.com/mindoc-org/mindoc.git
synced 2025-09-18 17:48:00 +08:00
增加redis
This commit is contained in:
@@ -19,8 +19,8 @@ import (
|
||||
beegoCache "github.com/astaxie/beego/cache"
|
||||
_ "github.com/astaxie/beego/cache/memcache"
|
||||
|
||||
// "github.com/astaxie/beego/cache/redis"
|
||||
// _ "github.com/astaxie/beego/cache/redis"
|
||||
"github.com/astaxie/beego/cache/redis"
|
||||
_ "github.com/astaxie/beego/cache/redis"
|
||||
"github.com/astaxie/beego/logs"
|
||||
"github.com/astaxie/beego/orm"
|
||||
"github.com/howeyc/fsnotify"
|
||||
@@ -326,7 +326,7 @@ func ResolveCommand(args []string) {
|
||||
beego.BConfig.WebConfig.StaticDir["/static"] = filepath.Join(conf.WorkingDirectory, "static")
|
||||
beego.BConfig.WebConfig.StaticDir["/uploads"] = uploads
|
||||
beego.BConfig.WebConfig.ViewsPath = conf.WorkingDir("views")
|
||||
beego.BConfig.WebConfig.Session.SessionCookieSameSite = http.SameSiteLaxMode
|
||||
beego.BConfig.WebConfig.Session.SessionCookieSameSite = http.SameSiteNoneMode
|
||||
|
||||
fonts := conf.WorkingDir("static", "fonts")
|
||||
|
||||
@@ -384,38 +384,38 @@ func RegisterCache() {
|
||||
memory := beegoCache.NewMemoryCache()
|
||||
beegoCache.DefaultEvery = cacheInterval
|
||||
cache.Init(memory)
|
||||
// } else if cacheProvider == "redis" {
|
||||
// //设置Redis前缀
|
||||
// if key := beego.AppConfig.DefaultString("cache_redis_prefix", ""); key != "" {
|
||||
// redis.DefaultKey = key
|
||||
// }
|
||||
// var redisConfig struct {
|
||||
// Conn string `json:"conn"`
|
||||
// Password string `json:"password"`
|
||||
// DbNum int `json:"dbNum"`
|
||||
// }
|
||||
// redisConfig.DbNum = 0
|
||||
// redisConfig.Conn = beego.AppConfig.DefaultString("cache_redis_host", "")
|
||||
// if pwd := beego.AppConfig.DefaultString("cache_redis_password", ""); pwd != "" {
|
||||
// redisConfig.Password = pwd
|
||||
// }
|
||||
// if dbNum := beego.AppConfig.DefaultInt("cache_redis_db", 0); dbNum > 0 {
|
||||
// redisConfig.DbNum = dbNum
|
||||
// }
|
||||
} else if cacheProvider == "redis" {
|
||||
//设置Redis前缀
|
||||
if key := beego.AppConfig.DefaultString("cache_redis_prefix", ""); key != "" {
|
||||
redis.DefaultKey = key
|
||||
}
|
||||
var redisConfig struct {
|
||||
Conn string `json:"conn"`
|
||||
Password string `json:"password"`
|
||||
DbNum int `json:"dbNum"`
|
||||
}
|
||||
redisConfig.DbNum = 0
|
||||
redisConfig.Conn = beego.AppConfig.DefaultString("cache_redis_host", "")
|
||||
if pwd := beego.AppConfig.DefaultString("cache_redis_password", ""); pwd != "" {
|
||||
redisConfig.Password = pwd
|
||||
}
|
||||
if dbNum := beego.AppConfig.DefaultInt("cache_redis_db", 0); dbNum > 0 {
|
||||
redisConfig.DbNum = dbNum
|
||||
}
|
||||
|
||||
// bc, err := json.Marshal(&redisConfig)
|
||||
// if err != nil {
|
||||
// beego.Error("初始化Redis缓存失败:", err)
|
||||
// os.Exit(1)
|
||||
// }
|
||||
// redisCache, err := beegoCache.NewCache("redis", string(bc))
|
||||
bc, err := json.Marshal(&redisConfig)
|
||||
if err != nil {
|
||||
beego.Error("初始化Redis缓存失败:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
redisCache, err := beegoCache.NewCache("redis", string(bc))
|
||||
|
||||
// if err != nil {
|
||||
// beego.Error("初始化Redis缓存失败:", err)
|
||||
// os.Exit(1)
|
||||
// }
|
||||
if err != nil {
|
||||
beego.Error("初始化Redis缓存失败:", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// cache.Init(redisCache)
|
||||
cache.Init(redisCache)
|
||||
} else if cacheProvider == "memcache" {
|
||||
|
||||
var memcacheConfig struct {
|
||||
|
Reference in New Issue
Block a user