Valkey: Configuring Valkey with Sidekiq
This documentation is part of the Using with Ruby guide. You can view the complete guide here: How to connect Valkey with Ruby.
👋 Welcome to the Stackhero documentation!
Stackhero offers a ready-to-use Valkey cloud solution that delivers numerous advantages, including:
Valkey Adminweb UI included.- Unlimited message size and transfers.
- One-click updates for easy maintenance.
- 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 Valkey cloud hosting solution!
Sidekiq will automatically use the Valkey server defined by the REDIS_URL environment variable.
You can set the REDIS_URL environment variable as follows, just replacing <password> and <XXXXXX> with your information:
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 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 raising an error
}
end
This configuration ensures that if your Valkey server becomes unavailable, the client will attempt to reconnect for 2 minutes before raising an error. This gives the Valkey server time to restart, for example. Depending on how you use Sidekiq in your application, you can adjust this setting to better fit your specific needs.
For more information about Sidekiq and Valkey, you can consult the official documentation here.