当前位置: 首页>>代码示例>>Golang>>正文


Golang Resp.Int方法代码示例

本文整理汇总了Golang中github.com/mediocregopher/radix/v2/redis.Resp.Int方法的典型用法代码示例。如果您正苦于以下问题:Golang Resp.Int方法的具体用法?Golang Resp.Int怎么用?Golang Resp.Int使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/mediocregopher/radix/v2/redis.Resp的用法示例。


在下文中一共展示了Resp.Int方法的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)
}
开发者ID:kung-foo,项目名称:dod-workshop,代码行数:59,代码来源:server.go


注:本文中的github.com/mediocregopher/radix/v2/redis.Resp.Int方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。