module Sidekiq::RedisConnection

def determine_redis_provider

def determine_redis_provider
  # If you have this in your environment:
  # MY_REDIS_URL=redis://hostname.example.com:1238/4
  # then set:
  # REDIS_PROVIDER=MY_REDIS_URL
  # and Sidekiq will find your custom URL variable with no custom
  # initialization code at all.
  #
  p = ENV["REDIS_PROVIDER"]
  if p && p =~ /:/
    raise <<~EOM
      REDIS_PROVIDER should be set to the name of the variable which contains the Redis URL, not a URL itself.
      Platforms like Heroku will sell addons that publish a *_URL variable.  You need to tell Sidekiq with REDIS_PROVIDER, e.g.:
      REDISTOGO_URL=redis://somehost.example.com:6379/4
      REDIS_PROVIDER=REDISTOGO_URL
    EOM
  end
  ENV[p.to_s] || ENV["REDIS_URL"]
end