Home > Blockchain >  ActionCable and Heroku Redis configuration
ActionCable and Heroku Redis configuration

Time:08-19

Last week RedisToGo was terminated on Herokum, leaving me with no choice but to find an alternative. I got a new subscription from Heroku: Heroku Redis.

Everything seems to work fine (all tasks/jobs) except things related to ActionCable.

[ActionCable] [#######] Registered connection (#########)
2022-08-17T00:40:23.213184 00:00 app[web.1]: #<Thread:0x00007e#####@/app/vendor/bundle/ruby/2.6.0/gems/actioncable-5.1.7/lib/action_cable/subscription_adapter/redis.rb:144 run> terminated with exception (report_on_exception is true):
2022-08-17T00:40:23.213206 00:00 app[web.1]: /app/vendor/bundle/ruby/2.6.0/gems/redis-4.1.4/lib/redis/client.rb:268:in `rescue in io': Connection lost (ECONNRESET) (Redis::ConnectionError)

I spent the last few days trying all sort of trick, but nothing work. My cable.yml file looks like:

production:
  adapter: redis
  url: <%= ENV['REDIS_URL'] %>

my redis.rb file looks like this:

uri = if Rails.env == 'production'
        URI.parse(ENV["REDIS_URL"])
      else
        URI.parse("redis://localhost:6379")
      end
Resque.redis = Redis.new(host: uri.host, port: uri.port, password: uri.password, ssl_params: { verify_mode: OpenSSL::SSL::VERIFY_NONE })

Am I missing certain parameters that results in the error ?

CodePudding user response:

I use Heroku Redis and here's what my cable.yml looks like:

development:
  adapter: redis
  url: redis://localhost:6379/1
  channel_prefix: myapp_development

test:
  adapter: redis
  url: redis://localhost:6379/1
  channel_prefix: myapp_test

production:
  adapter: redis
  url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %>
  channel_prefix: myapp_production
  ssl_params:
      verify_mode: <%= OpenSSL::SSL::VERIFY_NONE %>

If your tasks and jobs don't use Redis (if ActionCable is the only thing trying to use Redis) then your Redis might not actually be set up properly. Here's the documentation.

  1. Check to make sure Heroku actually set a REDIS_URL env variable:
$ heroku config | grep REDIS
> REDIS_URL: redis://h:[email protected]:111
  1. Make sure your instance has a normal configuration: https://devcenter.heroku.com/articles/heroku-redis#configuring-your-instance

Two other helpful sources:

  • Related