本文整理匯總了Golang中github.com/mediocregopher/radix/v2/redis.Resp.Bytes方法的典型用法代碼示例。如果您正苦於以下問題:Golang Resp.Bytes方法的具體用法?Golang Resp.Bytes怎麽用?Golang Resp.Bytes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/mediocregopher/radix/v2/redis.Resp
的用法示例。
在下文中一共展示了Resp.Bytes方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: doGET
func (c *Cluster) doGET(w http.ResponseWriter, r *http.Request) {
var err error
// path is already read because we are using http.StripPrefix
path := r.URL.Path
if path == "" {
http.NotFound(w, r)
return
}
slave := c.getReadSlave()
// this makes it easy to debug with curl -v
w.Header().Add("X-RRPROXY-SERVER", slave.Addr)
// get a redis client from the pool
client, err := slave.Get()
if err != nil {
log.Error(err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
// make sure we return it
defer slave.Put(client)
var resp *redis.Resp
// check to see if the key exists
resp = client.Cmd("EXISTS", path)
v, _ := resp.Int()
if v == 0 {
http.NotFound(w, r)
return
}
// here we introduce some artifical latency. without it, and with redis
// running on the same laptop as the server, other layers become the bottle
// neck rather than redis, which kinda defeats the purpose of this lab
if ForcedLatency > 0 {
resp = client.Cmd("DEBUG", "sleep", ForcedLatency.Seconds())
if resp.Err != nil {
log.Fatal(resp.Err)
}
}
// get the raw value as bytes and write it out
resp = client.Cmd("GET", path)
data, err := resp.Bytes()
if err != nil {
log.Error(err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.Write(data)
}