Valkey: Use Valkey 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 Valkey.

👋 Welcome to the Stackhero documentation!

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

  • Redis Commander web 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 Valkey cloud hosting solution!

To get started, you can install the redis gem with this command:

bundle add redis

Next, open the config/environments/production.rb file and include this line:

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

You will then need to set the VALKEY_URL environment variable. Here is an example of how you can format the URL with your information:

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

By default, caching is only enabled in the production environment. If you wish to test caching in development, modify the config/environments/development.rb file by adding the above configuration, and set config.action_controller.perform_caching = true to enable caching. A good way to verify that caching works is to start a Rails console (using bin/rails console) and test writing with Rails.cache.write("foo", "bar").

For more detailed information about configuring Valkey as a cache system for Ruby on Rails, you can consult the official Rails documentation here.

Sidekiq will automatically use the Valkey server configured in the REDIS_URL environment variable.

You can set the REDIS_URL environment variable with your information as follows:

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

For more insights into using Sidekiq with Valkey, you can consult the official documentation here.

Resque will automatically use the Valkey server defined in the REDIS_URL environment variable.

You can set the REDIS_URL environment variable with your information as follows:

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

For additional information on using Resque with Valkey, you can consult the official documentation here.