使用Go Redis客户端(Redigo)

huangapple go评论83阅读模式
英文:

using Go redis client (Redigo)

问题

我正在使用GO Redis客户端redigo将图像写入约20个Redis服务器。速度在这里是一个重要因素,我只是向Redis发送set命令,所以我使用Send和Flush而不调用Receive。几个小时后,客户端出现了"connection reset by peer"的错误。我想知道,这是否与我不调用Receive有关?也许我的RX队列只是因为我没有用Receive清空它而达到了最大容量?

谢谢。

英文:

I'm using GO redis client redigo to write image to ~20 redis servers.
speed is an important factor here and I'm just sending set commands to the redis so I'm using Send and Flush without calling Receive.
after a few hours I'm getting "connection reset by peer" on the client.
I was wondering, does it have something to do with the fact that I don't call Receive?
maybe my RX queue just getting to its max capacity because I don't empty it with Receive?

Thank you.

答案1

得分: 2

一个应用程序必须调用Receive来清除服务器的响应并检查错误。如果应用程序不使用流水线命令,则最好调用Do。Do函数将Send、Flush和Receive组合在一起。

如果你不关心错误,可以启动一个goroutine来读取响应:

go func(c redis.Conn) {
   for c.Err() == nil {
       c.Receive()
   }
}()
英文:

An application must call Receive to clear the responses from the server and to check for errors. If the application is not pipelining commands, then it's best to call Do. Do combines Send, Flush and Receive.

If you don't care about errors, then start a goroutine to read the responses:

go func(c redis.Conn) {
   for c.Err() == nil {
       c.Receive()
   }
}()

huangapple
  • 本文由 发表于 2015年6月5日 06:40:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/30655426.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定