Ruby: Redis
Connect Ruby and Ruby on Rails to Redis for fast caching and background job management
👋 Welcome to the Stackhero documentation!
Stackhero provides a ready-to-use Ruby cloud solution that delivers numerous advantages, including:
- Deploy your application in just a few seconds with a simple
git push.- Use your own domain name and take advantage of automatic configuration of HTTPS certificates for enhanced security.
- Benefit from automatic backups, one-click updates, and clear, transparent, and predictable pricing.
- Enjoy optimal performance and enhanced security thanks to a private, dedicated VM.
Save time and make your life easier: it only takes 5 minutes to try Stackhero's Ruby cloud hosting solution!
Redis (Remote Dictionary Server) is an in-memory database designed for speed and efficiency at scale. Its main strengths—high throughput, low latency, and flexible data structures—make it an essential tool for caching, real-time analytics, messaging, and much more.
Redis is distributed under the GNU AGPLv3 licence. If you are looking for a permissively licensed alternative, Valkey is a community-driven fork of Redis under the BSD licence. It is widely adopted by major organizations and is also available on Stackhero.
Redis supports multiple data types, including strings, hashes, lists, sets, and sorted sets. Its performance with large data volumes and real-time operations makes it especially valuable for Ruby and Ruby on Rails developers who want to improve application speed, scalability, and reliability.
With Redis, you can add features such as:
- Caching: Use Redis as a cache store in Rails to reduce database queries and speed up response times.
- Background job processing: Manage your job queues with libraries like Sidekiq and Resque, using Redis as a backend for reliable and high-performance background task execution.
- Real-time features: Build features like notifications, chat systems, or live analytics with Redis Pub/Sub, which enables fast message delivery between components.
Stackhero offers a ready-to-use Redis cloud service with features designed to save you time:
- Integrated Redis Commander web UI for easy data management.
- No limits on message size or transfer volume.
- One-click updates with no downtime.
- Consistent performance and enhanced security thanks to a dedicated private infrastructure.
You can get started quickly: deployment and setup take just a few minutes with Stackhero's Redis cloud hosting.
Configuring Redis as a cache system for Ruby on Rails
To integrate Redis caching, add the redis gem to your project:
bundle add redis
Then, update your config/environments/production.rb file:
config.cache_store = :redis_cache_store, { url: ENV["REDIS_URL"] }
Set the REDIS_URL environment variable. Replace <yourPassword> and <XXXXXX> with your credentials:
REDIS_URL="rediss://default:<yourPassword>@<XXXXXX>.stackhero-network.com:6380"
For more details and advanced options, see the official Rails caching documentation.
Configuring Redis with Sidekiq
Sidekiq will automatically use the Redis server specified in your REDIS_URL environment variable. Set it as shown below, updating <yourPassword> and <XXXXXX>:
REDIS_URL="rediss://default:<yourPassword>@<XXXXXX>.stackhero-network.com:6380"
To learn more, see the Sidekiq documentation on using Redis.
Configuring Redis with Resque
Resque also reads the Redis server from the REDIS_URL environment variable. Set it as shown below, replacing <yourPassword> and <XXXXXX>:
REDIS_URL="rediss://default:<yourPassword>@<XXXXXX>.stackhero-network.com:6380"
For more information on using Redis with Resque, see the official Resque documentation.