func main() {

	// 创建一个redis客户端
	var client redis.Client
	// 尝试从缓存中拿数据
	val, err := client.Get("Dog")

	// 检查缓存命中
	if err != nil {
		fmt.Println("Error fetching from", err)
	} else {
		fmt.Println("Cache hit")

		dog, err := DecodeData(val)
		if err != nil {
			fmt.Println("Error decoding data from memcache", err)
		} else {
			fmt.Println("Dog name is: ", dog.Name)
		}
	}

	// 创建对象实例
	spot := Dog{Name: "Spot", Color: "brown"}

	err = client.Set("Dog", EncodeData(spot))
	if err != nil {
		fmt.Println("Error setting memcache item", err)
	}

}
Пример #2
0
func (c App) Index(call string) revel.Result {
	var client redis.Client
	// c.Response.ContentType = "application/json"
	callsign, _ := client.Get("callsign:" + strings.ToUpper(call))
	log.Printf(string(callsign))
	// log.Printf(json.Marshal(callsign))
	callsign_data := string(callsign)
	return c.Render(call, callsign_data)
}