Ruby: Redis

Connect Ruby and Ruby on Rails with Redis for fast caching and background jobs

👋 Welcome to the Stackhero documentation!

Stackhero offers a ready-to-use Ruby cloud solution that provides a host of benefits, including:

  • Deploy your application in seconds with a simple git push.
  • Use your own domain name and benefit from the automatic configuration of HTTPS certificates for enhanced security.
  • Enjoy peace of mind with automatic backups, one-click updates, and straightforward, transparent, and predictable pricing.
  • Get optimal performance and robust security thanks to a private, dedicated infrastructure.

Save time and simplify your life: 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 core strengths: high throughput, low latency, and versatile data structures, make it a go-to tool for caching, real-time analytics, messaging, and more.

Redis is distributed under the GNU AGPLv3 license. If you need a permissively licensed alternative, Valkey is a community-driven fork of Redis under the BSD license. 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 useful for Ruby and Ruby on Rails developers who want to boost application speed, scalability, and reliability.

With Redis, you can add features such as:

  1. Caching: Use Redis as a cache store in Rails to reduce database queries and speed up response times.
  2. Background job processing: Power job queues with libraries like Sidekiq and Resque, using Redis as a backend for reliable and efficient background task execution.
  3. Real-time features: Build features like notifications, chat systems, or live analytics with Redis Pub/Sub, which enables fast message delivery between components.

Stackhero provides a ready-to-use Redis cloud service with features designed to save you time:

  • Built-in Redis Commander web UI for easy data management.
  • No limits on message size or transfer volume.
  • Seamless one-click updates.
  • Consistent performance and strong security with a dedicated private infrastructure.

You can get started quickly: deployment and setup take just a few minutes with Stackhero's Redis cloud hosting.

To integrate Redis caching, you can 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 actual credentials:

REDIS_URL="rediss://default:<yourPassword>@<XXXXXX>.stackhero-network.com:6380"

For more details and advanced options, see the Rails official caching documentation.

Sidekiq will automatically use the Redis server specified in your REDIS_URL environment variable. Set it as follows, updating <yourPassword> and <XXXXXX>:

REDIS_URL="rediss://default:<yourPassword>@<XXXXXX>.stackhero-network.com:6380"

To dive deeper, visit the Sidekiq documentation on Redis usage.

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 guidance on using Redis with Resque, check the Resque official documentation.