我在使用aws redis的Passport docker ruby 2.3中遇到一个奇怪的问题:
bad URI(is not URI?): 'redis://redis.xxx.ng.0001.apse1.cache.amazonaws.com:6379/1' (URI::InvalidURIError)
/usr/local/rvm/rubies/ruby-2.3.8/lib/ruby/2.3.0/uri/rfc3986_parser.rb:67:in `split'
/usr/local/rvm/rubies/ruby-2.3.8/lib/ruby/2.3.0/uri/rfc3986_parser.rb:73:in `parse'
/usr/local/rvm/rubies/ruby-2.3.8/lib/ruby/2.3.0/uri/common.rb:227:in `parse'
/usr/local/rvm/gems/ruby-2.3.8/gems/sidekiq-5.2.7/lib/sidekiq/redis_connection.rb:97:in `log_info'
/usr/local/rvm/gems/ruby-2.3.8/gems/sidekiq-5.2.7/lib/sidekiq/redis_connection.rb:31:in `create'
/usr/local/rvm/gems/ruby-2.3.8/gems/sidekiq-5.2.7/lib/sidekiq.rb:126:in `redis_pool'
/usr/local/rvm/gems/ruby-2.3.8/gems/sidekiq-5.2.7/lib/sidekiq.rb:94:in `redis'
我的sidekiq配置:
# ENV['REDIS_URL']= redis://redis.xxx.ng.0001.apse1.cache.amazonaws.com:6379/1
Sidekiq.configure_server do |config|
config.redis = { url: ENV['REDIS_URL'] }
end
Sidekiq.configure_client do |config|
config.redis = { url: ENV['REDIS_URL'] }
end
但是如果我跑步:
docker exec -it container_id bash
然后,Rails控制台似乎一切正常。
我也尝试过:
redis_url = ENV['REDIS_URL']
# The statement below parsed successfully thus the redis_url is correct
uri = URI.parse(redis_url)
redis_options = {
host: uri.host,
port: 6379,
db: uri.path[1..-1]
}
Sidekiq.configure_server do |config|
config.redis = redis_options
end
Sidekiq.configure_client do |config|
config.redis = redis_options
end
但是它引发了完全相同的错误。我可以在本地运行连接到本地redis的docker很好。我想知道ENV ['REDIS_URL']值可能有问题。
有人遇到此问题或任何线索吗?
我的环境是-客运码头工人红宝石2.3.8-AWS Elastic cache redis:5.0.5-sidekiq 5.2.7
[几个小时后,我才意识到容器中的redis_url被指向aws中已删除的Redis集群。我第一次启动Redis时默认将其设置为r5 16GM实例类型,这非常大且测试成本很高。我决定推出一个只有t2小的新玩具,并删除r5以便节省一些钱,但是在passenger-config中,我设置了REDIS_URL,Nginx覆盖了我在ECS任务中设置的env值。
ruby Redis提出的错误并不简单,并且有两个地方可以设置ENV(在Nginx配置和ECS-task中),使调试过程很痛苦。