1、完善日志配置

2、文章自动生成摘要
3、修正文档名称问题
4、修复Redis无法读取缓存的BUG
This commit is contained in:
lifei6671
2018-07-25 14:46:56 +08:00
parent 774530bbc2
commit 1cbdd4baca
11 changed files with 226 additions and 73 deletions

40
cache/cache.go vendored
View File

@@ -3,24 +3,56 @@ package cache
import (
"github.com/astaxie/beego/cache"
"time"
"encoding/gob"
"fmt"
"bytes"
"errors"
"github.com/astaxie/beego"
)
var bm cache.Cache
func Get(key string) interface{} {
func Get(key string,e interface{}) error {
return bm.Get(key)
val := bm.Get(key)
if val == nil {
return errors.New("cache does not exist")
}
if b,ok := val.([]byte); ok {
buf := bytes.NewBuffer(b)
decoder := gob.NewDecoder(buf)
err := decoder.Decode(e)
if err != nil {
fmt.Println("反序列化对象失败 ->", err)
}
return err
}
return errors.New("value is not []byte")
}
func GetMulti(keys []string) []interface{} {
return bm.GetMulti(keys)
}
func Put(key string, val interface{}, timeout time.Duration) error {
return bm.Put(key, val, timeout)
var buf bytes.Buffer
encoder := gob.NewEncoder(&buf)
err := encoder.Encode(val)
if err != nil {
beego.Error("序列化对象失败 ->",err)
return err
}
return bm.Put(key, buf.String(), timeout)
}
func Delete(key string) error {
return bm.Delete(key)
}