Ruby: Redis

How to connect Ruby with Redis

👋 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 and dedicated VM.

Save time and simplify your life: it only takes 5 minutes to try Stackhero's Ruby cloud hosting solution!

Redis, which stands for Remote Dictionary Server, is an in-memory database known for its exceptional performance.

Redis is available under the GNU AGPLv3 license. If you are looking for a permissively licensed alternative, Valkey is a popular community-maintained fork of Redis under the BSD license. It is widely recognized by well-known companies and is also available on Stackhero.

Often described as a NoSQL database, Redis supports a wide range of data structures, including strings, hashes, lists, sets, and sorted sets. Because it is fast and efficient with large volumes of data, Redis is a popular choice for caching, real-time analytics, messaging, and more.

Redis works very well with Ruby and Ruby on Rails when you want to improve performance, scalability, and flexibility. With Redis, Ruby developers can add features like caching, session management, real-time data processing, and background job processing.

Here are some common ways Redis is used with Ruby and Ruby on Rails:

  1. Caching: Redis can act as a cache store in Rails applications to reduce database load and improve response times.
  2. Background job processing: Redis is often used as the backend for popular job processing libraries like Sidekiq and Resque, helping background tasks run more efficiently and reliably.
  3. Real-time features: Redis Pub/Sub makes it possible to build real-time features such as notifications, chat systems, and live analytics by enabling fast message delivery between application components.

Stackhero offers a ready-to-use Redis cloud solution with several useful benefits:

  • Redis Commander web UI included.
  • Unlimited message size and transfers.
  • Simple updates in just one click.
  • Strong performance and solid security powered by a private and dedicated VM.

Save time and simplify deployment. It only takes 5 minutes to try Stackhero's Redis cloud hosting solution.

To get started, you can install the redis gem:

bundle add redis

Next, you can update the config/environments/production.rb file with this line:

config.cache_store = :redis_cache_store, { url: ENV["REDIS_URL"] }

After that, you can define the REDIS_URL environment variable. This example shows the format to use. Just replace <yourPassword> and <XXXXXX> with your own values:

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

If you would like more details about using Redis as a cache system in Ruby on Rails, you can check the official Rails documentation.

Sidekiq automatically uses the Redis server defined in the REDIS_URL environment variable.

You can define REDIS_URL like this, replacing <yourPassword> and <XXXXXX> with your own values:

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

If you would like to learn more about Sidekiq and Redis, you can check the official documentation.

Resque automatically uses the Redis server defined in the REDIS_URL environment variable.

You can define REDIS_URL like this, replacing <yourPassword> and <XXXXXX> with your own values:

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

If you would like to learn more about Resque and Redis, you can check the official documentation.