wessman.co

Published on

Upgrading Heroku Redis version on a Rails app with Sidekiq

Author

Heroku are great at pushing for upgrading to latest version of their hosted addons, below I summarized the steps I had to take to upgrade.

The email notification I received from Heroku looked like this:

On March 10, 2021, we announced the Heroku Redis Hobby Tier Version Deprecation. Your Redis database redis-name on app-name is running the deprecated version (5.0.12) which will not be supported after June 30, 2021. We recommended upgrading your Redis database to the latest version supported by Heroku, which is currently 6.0.12. We perform heavy testing and validation work on all new Redis releases, including testing the upgrade procedure, and are careful to only recommend versions that we trust. You can upgrade your Redis database to the latest default version by creating a fork on the latest version and promoting it as your active add-on. You can read more about this procedure in our Dev Center article. If you do not take action, we will upgrade your Redis database on or after June 30, 2021.

Let's go!

Beware!

  • Redis version 6 has some changes to TLS on Heroku.
  • Redis via TLS does not work out of the box on Rails with Sidekiq.
  • For hobby-dev (the free Redis plan on Heroku) TLS support is added on a separate url accessible through REDIS_TLS_URL.
  • For Premium, Private and Shield plans the REDIS_URL will be TLS.

1. Support using TLS for Redis in Rails with Sidekiq

The solution was found in the StackOverflow question and linked blog post:

Create or edit your config/initializer/sidekiq.rb to include

Sidekiq.configure_server do |config|
  config.redis = { ssl_params: { verify_mode: OpenSSL::SSL::VERIFY_NONE } }
end

Sidekiq.configure_client do |config|
  config.redis = { ssl_params: { verify_mode: OpenSSL::SSL::VERIFY_NONE } }
end

Why do we disable SSL-verification?

Heroku handles the networking between your application and Heroku Redis with self signed certificates and it does not work with SSL-verification. For more background and examples see:

2. Upgrading Redis version

  • This was tested from Redis version 4.x and 5.x on my low-traffic personal projects. Take precautions!
  • This change requires some downtime, so schedule it accordingly.
  • Make sure the changes in step 1 is deployed and live.
  • Heroku's instructions are great.
  1. Put application in maintenance mode and spin down your worker dynos.
  2. Get value of your current REDIS_URL, use Heroku UI or heroku config | grep REDIS_URL, I will refer to it as redis_url.
  3. Check what plan you use and memorize the name: Heroku Redis, I use hobby-dev in this example.
  4. # <redis_url> is the value from step 2.
    heroku addons:create heroku-redis:hobby-dev --fork <redis_url>
    
  5. $ heroku redis:info
    === redis-triangular-00001 (REDIS_URL)
    Plan:                   Hobby Dev
    Status:                 available
    Created:                2019-05-01 11:03
    Version:                4.0 (End of Life)
    Timeout:                300
    Maxmemory:              noeviction
    Maintenance:            not required
    Maintenance window:     Thursdays 22:00 to Fridays 02:00 UTC
    Persistence:            None
    HA Status:              Unavailable
    Requires TLS:           No
    Keyspace Notifications: Disabled
    === redis-graceful-00002 (HEROKU_REDIS_BRONZE_TLS_URL, HEROKU_REDIS_BRONZE_URL)
    Plan:                   Hobby Dev
    Status:                 creating
    Created:                2021-04-05 13:21
    Version:                6.0.12
    Timeout:                300
    Maxmemory:              noeviction
    Maintenance:            not required
    Maintenance window:     Thursdays 20:00 to Fridays 00:00 UTC
    Persistence:            None
    HA Status:              Unavailable
    Requires TLS:           Yes
    Keyspace Notifications: Disabled
    
  6. Check the status of the new Redis instance, it will change to preparing (fork in progress) and eventually available.
  7. When status is available, get the name of the new instance, in this example redis-graceful-00002:
    heroku redis:promote redis-graceful-0002
    
  8. Spin up your worker dynos and exit maintenance mode.
  9. Check your Redis-connection through e.g. the Sidekiq dashboard.
  10. Remove the unused Redis addon when everything is live, in this example:
    heroku addons:destroy redis-triangular-00001
    

3. Using REDIS_TLS_URL with Sidekiq

If you are using the hobby-dev Redis plan the default REDIS_URL will not use TLS.

Sidekiq will pick up the REDIS_URL by default, to use the TLS-url we can set:

heroku config:set REDIS_PROVIDER=REDIS_TLS_URL

This behaviour is described in the Sidekiq wiki.


Thank you for reading, hit me up on Twitter if you want to discuss anything!

Twitterdavidwessman