beego中cache缓存模块redis

注意加上  _ “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"))
}
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值