ruby-on-railsherokumemcacheddalli

ECONNREFUSED: Connection Refused localhost:11211 - Dalli / Memcachier / Heroku


So on heroku I am getting this issue. I can't quite figure out why this is happening.

heroku run rails c
 > cache = Dalli::Client.new
 > Rails.cache.write('memcachier', 'rocks')
Dalli::Server#connect localhost:11211

localhost:11211 failed (count: 1) Errno::ECONNREFUSED: Connection refused - send
localhost:11211 failed (count: 1) Errno::ECONNREFUSED: Connection refused - send
localhost:11211 is down
localhost:11211 is down

Solution

  • It sounds like you either don't have the memcachier gem installed, or you haven't added the memcachier addon to your Heroku app.

    You can install the memcachier addon from the command line:

    heroku addons:add memcachier:dev
    

    Then make sure that you have both the dalli gem and the memcachier gems in your Gemfile

    gem 'dalli'
    gem 'memcachier'
    

    Run bundle install, check in your updated Gemfile and Gemfile.lock, push it all up to Heroku and try the Rails.cache.write again.