Redis®*: Configuring Redis with Sidekiq

This documentation is part of the Using with Ruby guide. You can view the complete guide here: How to connect Redis with Ruby.

👋 Welcome to the Stackhero documentation!

Stackhero provides a ready-to-use Redis cloud solution offering numerous advantages, including:

  • Redis Commander web interface included.
  • Unlimited message size and transfers.
  • Updates made easy with just one click.
  • Optimal performance and enhanced security thanks to a private, dedicated infrastructure.

Save time and make your life easier: it only takes 5 minutes to try Stackhero's Redis cloud hosting solution!

Sidekiq will automatically use the Redis server defined in the REDIS_URL environment variable.

You can set the REDIS_URL environment variable as follows, replacing <password> and <XXXXXX> with your details:

REDIS_URL="rediss://default:<password>@<XXXXXX>.stackhero-network.com:<PORT_TLS>"

By default, Sidekiq is configured without any tolerance for network disruptions. To improve this, we recommend modifying the Sidekiq client configuration in config/initializers/sidekiq.rb to enhance stability:

# File config/initializers/sidekiq.rb
Sidekiq.configure_client do |config|
  config.redis = {
    network_timeout: 5, # Set the timeout to 5 seconds
    pool_timeout: 5, # Set the timeout to 5 seconds
    reconnect_attempts: Array.new(240, 0.5) # Attempt to reconnect 240 times, every 0.5 second (120 seconds/2 minutes in total) before raising an error
  }
end

This configuration ensures that if your Redis server becomes unavailable, the client will attempt to reconnect for 2 minutes before reporting an error. This gives the Redis server time to restart, for example. Depending on your Sidekiq usage, you can adjust this setting to suit your specific needs.

For more information about Sidekiq and Redis, you can refer to the official documentation here.