gpt4 book ai didi

ruby - Rails 应用程序中的 Redis::TimeoutError

转载 作者:IT王子 更新时间:2023-10-29 05:55:15 26 4
gpt4 key购买 nike

我的应用程序中不断出现 Redis::Timeout 错误(在 UI 和后台作业中)。我正在为 Redis 使用 AWS ElastiCache 服务。

这就是我创建 Redis 连接的方式。在我的 config/application.rb 中,我有:

$redis = Redis.new(host: REDIS_HOST, port: REDIS_PORT, db: REDIS_DB)

如何避免出现超时错误?我使用的默认连接设置如下:

> $redis.client.options[:reconnect_attempts]
=> 1
> $redis.client.options[:timeout]
=> 5.0
> $redis.client.options[:tcp_keepalive]
=> 0
> $redis.client.options[:inherit_socket]
=> false

最佳答案

您应该在 Connection Pool Gem 的帮助下汇集您的 Redis 连接如果问题仍然存在,则增加超时值:

ConnectionPool.new(size: 5, timeout: 3) {Redis.new({:host => 'localhost', :port => 6379, :db => 1, :timeout => 240})}

Redis Gem

关于ruby - Rails 应用程序中的 Redis::TimeoutError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29410469/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com