缓存驱动更换成功,支持3级缓存,memory,以及db

This commit is contained in:
hoteas
2021-05-28 22:52:22 +08:00
parent fc315064e7
commit 1101937028
11 changed files with 369 additions and 126 deletions
+23 -10
View File
@@ -8,13 +8,26 @@ import (
)
type CacheRedis struct {
Host string
Pwd string
Time int64
conn redis.Conn
tag int64
TimeOut int64
DbSet bool
SessionSet bool
Host string
Pwd string
Port int64
conn redis.Conn
tag int64
ContextBase
Error
*Error
}
func (this *CacheRedis) GetError() *Error {
return this.Error
}
func (this *CacheRedis) SetError(err *Error) {
this.Error = err
}
//唯一标志
@@ -28,7 +41,7 @@ func (this *CacheRedis) GetTag() int64 {
func (this *CacheRedis) reCon() bool {
var err error
this.conn, err = redis.Dial("tcp", this.Host)
this.conn, err = redis.Dial("tcp", this.Host+":"+ObjToStr(this.Port))
if err != nil {
this.conn = nil
this.Error.SetError(err)
@@ -129,15 +142,15 @@ func (this *CacheRedis) Cache(key string, data ...interface{}) *Obj {
//添加缓存
if len(data) == 1 {
if this.Time == 0 {
if this.TimeOut == 0 {
//this.Time = Config.GetInt64("cacheShortTime")
}
tim += this.Time
tim += this.TimeOut
}
if len(data) == 2 {
this.Error.SetError(nil)
tempt := ObjToInt64(data[1], &this.Error)
tempt := ObjToInt64(data[1], this.Error)
if tempt > tim {
tim = tempt