Redis®*: Using Redis with Ruby and Ruby on Rails
This documentation is part of the Getting started guide. You can view the complete guide here: Quick guide to getting started with Redis.
👋 Welcome to the Stackhero documentation!
Stackhero offers a ready-to-use Redis cloud solution that provides a host of benefits, including:
Redis Commanderweb UI included.- Unlimited message size and transfers.
- Effortless updates with just a click.
- Optimal performance and robust security powered by a private and dedicated VM.
Save time and simplify your life: it only takes 5 minutes to try Stackhero's Redis cloud hosting solution!
Configure Redis as a cache system for Ruby on Rails
To get started, you can install the redis gem with:
bundle add redis
Next, you can open config/environments/production.rb and add the following line:
config.cache_store = :redis_cache_store, { url: ENV["REDIS_URL"] }
Then you can define the REDIS_URL environment variable. Here is a template you can adapt with your own details:
REDIS_URL="rediss://default:<yourPassword>@<XXXXXX>.stackhero-network.com:<PORT_TLS>"
By default, caching is enabled only in the production environment. If you would like to test caching during development, you can also update
config/environments/development.rb. Add the same configuration shown above and includeconfig.action_controller.perform_caching = trueto enable caching. One simple way to confirm that caching is working is to start a Rails console withbin/rails consoleand tryRails.cache.write("foo", "bar").
For more details about using Redis as a cache store in Ruby on Rails, you can check the official Rails documentation.
Configure Redis for Sidekiq
Sidekiq automatically uses the Redis server defined in the REDIS_URL environment variable.
You can set REDIS_URL with your own connection details like this:
REDIS_URL="rediss://default:<yourPassword>@<XXXXXX>.stackhero-network.com:<PORT_TLS>"
For more details about using Sidekiq with Redis, you can refer to the official Sidekiq documentation.
Configure Redis for Resque
Like Sidekiq, Resque uses the Redis server defined in the REDIS_URL environment variable.
You can set REDIS_URL with your own details like this:
REDIS_URL="rediss://default:<yourPassword>@<XXXXXX>.stackhero-network.com:<PORT_TLS>"
For more information about using Resque with Redis, you can visit the official Resque documentation.