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) } }
func setToBeHandled(input string) { c := redis.Client{Addr: addr, Password: pass} c.Auth(pass) c.Set(input, "1") c.Expire(input, EXPIRETIME) }