Ruby: Redis
Connect Ruby and Ruby on Rails to Redis for fast caching and background task management
👋 Welcome to the Stackhero documentation!
Stackhero provides a ready-to-use Ruby cloud solution offering a range of advantages, including:
- Deploy your application within seconds using a simple
git push.- Use your own domain name and benefit from the automatic configuration of HTTPS certificates for enhanced security.
- Take advantage of automatic backups, one-click updates, and clear, transparent, and predictable pricing.
- Enjoy 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 Ruby cloud hosting solution!
Redis (Remote Dictionary Server) is an in-memory database designed to deliver speed and efficiency at scale. Its main strengths—high throughput, low latency, and versatile 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 organisations 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 particularly useful for Ruby and Ruby on Rails developers looking 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 task 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: Develop features such as notifications, chat systems, or live analytics with Redis Pub/Sub, which enables rapid message delivery between components.
Stackhero offers a ready-to-use Redis cloud service with features designed to save you time:
- Integrated Redis Commander web interface 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"
For further information, 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 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.