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 that delivers numerous advantages, including:
- Redis Commander web interface included.
- Unlimited message size and transfers.
- One-click simplified updates.
- 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 like this, replacing <password> and <XXXXXX> with your information:
REDIS_URL="rediss://default:<password>@<XXXXXX>.stackhero-network.com:<PORT_TLS>"
By default, Sidekiq is configured in a way that does not provide any tolerance for network disruptions. To improve this, we recommend updating the Sidekiq client configuration in config/initializers/sidekiq.rb to increase 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) # Try to reconnect 240 times, every 0.5 second (120 seconds/2 minutes in total) before triggering 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 better fit your specific needs.
For more information about Sidekiq and Redis, you can refer to the official documentation here.