简体   繁体   English

想在Heroku上使用Redis(Redis :: CannotConnectError(在127.0.0.1:6379上连接到Redis时出错(ECONNREFUSED)))

[英]Want to use Redis on Heroku (Redis::CannotConnectError ( Error connecting to Redis on 127.0.0.1:6379 (ECONNREFUSED)) )

I want to use Redis on Heroku but I got this error Redis::CannotConnectError (Error connecting to Redis on 127.0.0.1:6379 (ECONNREFUSED)) . 我想在Heroku上使用Redis但我收到此错误Redis::CannotConnectError (Error connecting to Redis on 127.0.0.1:6379 (ECONNREFUSED))

I checked these , but didn't get helped. 我检查了这些,但没有得到帮助。 Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED , deploying redis to heroku unable to connect , How to get Redis to start on Heroku? Redis连接到127.0.0.1:6379失败 - 连接ECONNREFUSED将redis部署到heroku无法连接如何让Redis在Heroku上启动? .

I use Ruby 2.0.0p247 and Rails4. 我使用Ruby 2.0.0p247和Rails4。 I'm using puma. 我正在使用美洲狮。

I use RedisToGo(nano) and, in /config/initializers/redis.rb I write this. 我使用RedisToGo(nano),在/config/initializers/redis.rb中我写了这个。

uri = URI.parse(ENV["REDISTOGO_URL"] || "redis://localhost:6379/" )
$redis = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)

I checked "REDISTOGO_URL" is the same URL that I can see when $ heroku config . 我检查过“REDISTOGO_URL”是我在$ heroku config时可以看到的URL。

I did Redis restart on Heroku GUI, but it doesn't work. 我在Heroku GUI上重启Redis,但它不起作用。

Please tell me anything I need to do. 请告诉我我需要做的任何事情。 Thank you for your help. 谢谢您的帮助。

Check which ENV variable should contain redis configuration 检查哪个ENV变量应包含redis配置

For example if you are going to use Redis for Sidekiq you need to map ENV["REDISTOGO_URL"] to ENV["REDIS_PROVIDER"] because Sidekiq is expecting to get redis configuration from ENV["REDIS_PROVIDER"] 例如,如果您要将Redis用于Sidekiq,则需要将ENV [“REDISTOGO_URL”]映射到ENV [“REDIS_PROVIDER”],因为Sidekiq期望从ENV [“REDIS_PROVIDER”]获得redis配置

You can do it this way 你可以这样做

heroku config:set REDIS_PROVIDER=REDISTOGO_URL

Also you don't need to URI.parse , Redis will do it instead of you in case it is needed. 此外,您不需要URI.parse ,Redis会在需要时代替您。

$redis = Redis.new(url: ENV['REDISTOGO_URL' || "redis://localhost:6379/"])

I suggest to use the gem figaro to set ENV variables for your local development. 我建议使用gem figaro为您的本地开发设置ENV变量。 Thus you remove OR statement 因此,您删除OR语句

$redis = Redis.new(url: ENV['REDISTOGO_URL'])

and set alternative value in your config/application.yml 并在config / application.yml中设置替代值

REDISTOGO_URL: redis://127.0.0.1:6379 

You're trying to connect to your own computer (note 127.0.0.1 == localhost). 您正在尝试连接到自己的计算机(请注意127.0.0.1 == localhost)。 I'm guessing that's not the Redis server you're looking for :) 我猜这不是你正在寻找的Redis服务器:)

Looks like ENV["REDISTOGO_URL"] isn't properly set. 看起来ENV["REDISTOGO_URL"]没有正确设置。


Also, just a side note, look up Redis To Go if you haven't already, which is what most people use as a Redis server in conjunction with Heroku. 另外,只是旁注,如果你还没有,请查看Redis To Go ,这是大多数人与Heroku一起用作Redis服务器的原因。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Rails-Redis :: CannotConnectError:在本地主机上连接Redis时出错:6379(Errno :: ECONNREFUSED) - Rails - Redis::CannotConnectError: Error connecting to Redis on localhost:6379 (Errno::ECONNREFUSED) Redis :: CannotConnectError(在localhost:6379(Errno :: ECONNREFUSED)上连接到Redis时出错): - Redis::CannotConnectError (Error connecting to Redis on localhost:6379 (Errno::ECONNREFUSED)): GiLab CI-Redis :: CannotConnectError:在127.0.0.1:6379上连接到Redis时出错 - GiLab CI - Redis::CannotConnectError: Error connecting to Redis on 127.0.0.1:6379 Sidekiq Redis :: CannotConnectError:生产时在127.0.0.1:6379上连接到Redis时出错 - Sidekiq Redis::CannotConnectError: Error connecting to Redis on 127.0.0.1:6379 on production 在 Rails 应用程序上的 127.0.0.1:6379(ECONNREFUSED) 上连接到 Redis 时出错 - Error connecting to Redis on 127.0.0.1:6379(ECONNREFUSED) on rails application rails + docker + sidekiq +错误连接到127.0.0.1:6379上的Redis(Errno :: ECONNREFUSED) - rails + docker + sidekiq + Error connecting to Redis on 127.0.0.1:6379 (Errno::ECONNREFUSED) 在 127.0.0.1:6379 (Errno::ECONNREFUSED) 上连接到 Redis 时出错 - Wercker - Error connecting to Redis on 127.0.0.1:6379 (Errno::ECONNREFUSED) - Wercker (在localhost:6379(Errno :: ECONNREFUSED)上连接到Redis时出错): - (Error connecting to Redis on localhost:6379 (Errno::ECONNREFUSED)): Redis / Resque [在本地主机上连接到Redis时出错:6379(ECONNREFUSED)] - Redis/Resque [Error connecting to Redis on localhost:6379 (ECONNREFUSED)] Sidekiq 在 docker-compose 上的 127.0.0.1:6379 (Errno::ECONNREFUSED) 上连接到 Redis 时出错 - Sidekiq Error connecting to Redis on 127.0.0.1:6379 (Errno::ECONNREFUSED) on docker-compose
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM