beegoにおけるcacheキャッシュモジュールredis
1254 ワード
注意プラス_「github.com/astaxie/beego/cache/redis」という言葉
package main
import (
"encoding/json"
"fmt"
"github.com/astaxie/beego"
"github.com/astaxie/beego/cache"
_ "github.com/astaxie/beego/cache/redis"
"time"
"strings"
)
func main() {
mstr:=map[string]string{}
mstr["key"]="chatengine"
mstr["conn"]=":6379"
mstr["dbNum"]="0"
bytes, _ := json.Marshal(mstr)
// redis
cache_conn, err := cache.NewCache("redis", string(bytes))
if err != nil {
fmt.Println(err)
}
timeoutDuration := 10000000 * time.Second
err = cache_conn.Put("wilson1231111", "xu", timeoutDuration)
if err != nil {
fmt.Println(" , :",err)
}else {
fmt.Println("redis ")
}
if areaData := cache_conn.Get("area");areaData!=nil{
beego.Info("get data from cache===========")
//resp["data"] = areaData
fmt.Println(" redis :",areaData)
}else {
fmt.Println(" MySQL")
}
fmt.Println(strings.Index("i am a good man", "haha"))
}