本文整理汇总了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)
}