2016-10-05 15:36
浏览 1.4k

SetConnMaxLifetime如何在Golang数据库/ SQL上工作

I am confused by the documentation of the func (db *DB) SetConnMaxLifetime(d time.Duration) that states:

SetConnMaxLifetime sets the maximum amount of time a connection may be reused.

Expired connections may be closed lazily before reuse.

Does this mean that idle connections are closed after d has expired or that connections are closed in any case (either idle or not) after d has expired like SetConnMaxLifetime suggests? Also what does closing lazily mean in this case and is it possible to implement a timeout using this method?

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

func(db * DB)SetConnMaxLifetime(d time.Duration)的#DB.SetConnMaxLifetime“ rel =” nofollow“>文档,其内容为: < blockquote>



这是否意味着空闲连接 在 d 到期后关闭,或者在 d 到期后在任何情况下都关闭连接(无论是否空闲),如 SetConnMaxLifetime 所示?\ n在这种情况下,关闭也意味着什么呢?是否可以使用此方法实现超时?

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

1条回答 默认 最新

  • duanming7833 2016-10-05 15:42

    No, sql.DB will not close an active connection. The cleaner only runs over the free connection pool.

    点赞 评论

相关推荐 更多相似问题