英文:
Relation between PoolTimeout, IdleTimeout & IdleCheckFrequency in go-redis
问题
有人可以告诉我在go-redis中的PoolTimeout、IdleTimeout和IdleCheckFrequency之间的关系吗?
疑问:
- 如果我指定了
PoolTimeout
为20毫秒,IdleTimeout
为20毫秒,PoolSize
为100,IdleCheckFrequency
为1分钟。假设连接池中的所有连接都被使用,并且一个连接完成其操作。那么在1分钟的间隔内,请求一个新的连接会等待IdleCheck运行吗? - 如果我指定了
PoolSize
为100,即使没有正在执行的Redis操作,客户端是否会保持100个与Redis的连接打开?
环境:
- Go - 1.7.4
- Redis - 3.2.6
- Go-Redis - v5.2
英文:
Can someone let me know the relation between PoolTimeout, IdleTimeout & IdleCheckFrequency in go-redis?
Doubts:-
- If I specify
PoolTimeout
20ms,IdleTimeout
20ms,PoolSize
100 &IdleCheckFrequency
1 min. Let's say all the connection in the pool are used and a connection finishes its operation. Then will the request for a new connection wait till the IdleCheck is run in 1 min interval? - If I specify
PoolSize
100 will the client keep open 100 connections to redis even if there is no active client operation being performed to Redis?
Environment:-
- Go - 1.7.4
- Redis - 3.2.6
- Go-Redis - v5.2
答案1
得分: 4
这个问题在GitHub上已经有答案了,在这里。我将以下相关部分贴在下面:
> PoolSize 限制了最大的打开连接数。如果应用程序处于空闲状态,go-redis 就不会打开任何连接。
>
> 当有命令需要处理且连接池中没有空闲连接时,会打开一个新的连接。空闲连接在空闲时间超过 IdleTimeout 后会被关闭。
>
> IdleCheckFrequency 指定了我们检查连接是否过期的频率。这在应用程序处于空闲状态且没有活动时是必需的。通常,当 go-redis 请求连接池提供一个(健康的)连接时,空闲连接会被关闭。
英文:
This has been answered in github here. Just posting the relevant parts below:-
> PoolSize limits max number of open connections. If app is idle then
> go-redis does not open any connections.
>
> New connection is opened when there is a command to process and there
> are no idle connections in the pool. Idle connections are closed after
> they are idle for IdleTimeout.
>
> IdleCheckFrequency specifies how often we check if connection is
> expired. This is needed in case app is idle and there is no activity.
> Normally idle connections are closed when go-redis asks pool for a
> (healthy) connection.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论