本文整理汇总了Golang中menteslibres/net/gosexy/redis.Client.Set方法的典型用法代码示例。如果您正苦于以下问题:Golang Client.Set方法的具体用法?Golang Client.Set怎么用?Golang Client.Set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类menteslibres/net/gosexy/redis.Client
的用法示例。
在下文中一共展示了Client.Set方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: handler
func handler(p *httputil.ReverseProxy, redisClient *redis.Client) func(http.ResponseWriter, *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
hash := hashKey(r)
serializableResponse := SerializableResponse{make(map[string][]string), nil}
s, err := redisClient.Get(hash)
if err != nil { // The request is not cached
rec := httptest.NewRecorder()
log.Println("Non cached: " + hash)
// Perform the real request and cache it
p.ServeHTTP(rec, r)
for k, v := range rec.Header() {
serializableResponse.Header[k] = v
}
serializableResponse.Body = rec.Body.Bytes()
jsonResponse, err := json.Marshal(serializableResponse)
if err != nil {
panic(err)
}
redisClient.Set(hash, jsonResponse)
w.Header().Set("X-Eidetic", "Live request")
} else { // The request is cached
log.Println("Cached!: " + hash)
// Load the cached request
err = json.Unmarshal([]byte(s), &serializableResponse)
if err != nil {
panic(err)
}
w.Header().Set("X-Eidetic", "Cached request")
}
//Copy the data to the actual ResponseWriter
// log.Println("\n\n\nResponse Headers:")
for k, v := range serializableResponse.Header {
w.Header()[k] = v
// log.Println(k + ": ")
// for _, str := range v {
// log.Println(" " + str)
// }
}
w.Write([]byte(serializableResponse.Body))
// log.Println("\nResponse body:\n" + string(serializableResponse.Body))
}
}