dongwei3172
2019-02-25 12:43
浏览 444

redigo是否重新连接到服务器?

I am using Redigo to connect to redis server through golang.

redisConnection, err = redis.Dial("tcp", "...")
redisConnection.Do(..., ...)

If I restart my server, I am unable to execute any command using the same redisConnection. Shouldn't it reconnect when I execute Do again?

图片转代码服务由CSDN问答提供 功能建议

我正在使用 Redigo 通过golang连接到Redis服务器。

  redisConnection,err = redis.Dial(” tcp“,” ...“)
redisConnection  .Do(...,...)
   
 
 

如果重新启动服务器,则无法使用相同的 redisConnection执行任何命令。 再次执行 Do 时,它不应该重新连接吗?

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dqyknf4423 2019-02-25 14:34
    已采纳

    No, your assumption is not correct. Using the Dial function it returns a single connection when the server terminates the connection, the client is not able to reconnect.
    You should use redis.Pool and it should be able to auto-reconnect when you ask for a new connection, the function is: pool.Get()

    已采纳该答案
    打赏 评论
  • dougou7782 2019-02-28 06:48

    redisConnection.Err() returns a non nil value if the connection is not usable. We can Dial again in that case.

    打赏 评论

相关推荐 更多相似问题