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

标签 ruby redis timeout

我的应用程序中不断出现 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/

相关文章:

c - hiredis 因 TLS 而失败

timeout - 如何优雅地终止无响应的 tcl 脚本?

ruby - MacOS Passenger Ruby PG Gem 段错误

ruby - 配置错误 LoadError : cannot load such file -- chef_handler_foreman (require statement in/etc/chef/client. rb)

ruby - RHEL 5.3 的最新 redhat 支持的 ruby​​ 版本?

arrays - Ruby:删除数组中重复值的所有实例

redis - Redis PubSub 订阅机制是如何工作的?

java - 使用 java 从 aws elasticache 中放置和获取数据

javascript - Promise 的执行顺序

http - 实际中空闲 HTTP 连接的理想超时长度