Redis®*: Getting started
Quick guide to getting started with Redis
👋 Welcome to the Stackhero documentation!
Stackhero offers a ready-to-use Redis cloud solution that provides a host of benefits, including:
Redis Commanderweb 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 Redis cloud hosting solution!
Redis is a powerful and extremely fast in-memory database that can serve several roles. You can use it as a cache, a key-value store, a real-time data structure engine, or a publish/subscribe and event system.
Redis is open source again: since Redis 8 (May 2025) it has been available under the GNU AGPLv3 licence. If you prefer a permissively licensed (BSD) drop-in alternative, the community-driven fork Valkey is also available on Stackhero.
To help you get started, we have shared code examples that show how to connect to a Redis instance. You can find them in this GitHub repository: https://github.com/stackhero-io/redisGettingStarted.
Using Redis with Ruby and Ruby on Rails
Configure Redis as a cache system for Ruby on Rails
To get started, you can install the redis gem with:
bundle add redis
Next, you can open config/environments/production.rb and add the following line:
config.cache_store = :redis_cache_store, { url: ENV["REDIS_URL"] }
Then you can define the REDIS_URL environment variable. Here is a template you can adapt with your own details:
REDIS_URL="rediss://default:<yourPassword>@<XXXXXX>.stackhero-network.com:<PORT_TLS>"
By default, caching is enabled only in the production environment. If you would like to test caching during development, you can also update
config/environments/development.rb. Add the same configuration shown above and includeconfig.action_controller.perform_caching = trueto enable caching. One simple way to confirm that caching is working is to start a Rails console withbin/rails consoleand tryRails.cache.write("foo", "bar").
For more details about using Redis as a cache store in Ruby on Rails, you can check the official Rails documentation.
Configure Redis for Sidekiq
Sidekiq automatically uses the Redis server defined in the REDIS_URL environment variable.
You can set REDIS_URL with your own connection details like this:
REDIS_URL="rediss://default:<yourPassword>@<XXXXXX>.stackhero-network.com:<PORT_TLS>"
For more details about using Sidekiq with Redis, you can refer to the official Sidekiq documentation.
Configure Redis for Resque
Like Sidekiq, Resque uses the Redis server defined in the REDIS_URL environment variable.
You can set REDIS_URL with your own details like this:
REDIS_URL="rediss://default:<yourPassword>@<XXXXXX>.stackhero-network.com:<PORT_TLS>"
For more information about using Resque with Redis, you can visit the official Resque documentation.
Handle PHP sessions with Redis
If you would like to store PHP sessions on Stackhero for Redis, you can use the following example:
<?php
// Parse Redis URL
$redis_url = parse_url("rediss://default:<yourPassword>@<XXXXXX>.stackhero-network.com:<PORT_TLS>")
// Configure session handler
ini_set("session.save_handler", "redis")
ini_set("session.save_path", "tls://{$redis_url["host"]}:{$redis_url["port"]}?auth={$redis_url["pass"]}&timeout=5")
// Start the session
session_start()
?>
Enhancing Redis security
Keeping your Redis instance secure is important, and a few simple measures can make a big difference.
Encrypt communications with Redis (TLS)
By default, Redis does not encrypt network traffic. On Stackhero, TLS encryption is enabled by default.
To benefit from this, you can configure your Redis client to use TLS and connect through the <PORT_TLS> port. It is best to use <PORT_CLEAR> only for specific cases where unencrypted traffic is appropriate, while <PORT_TLS> provides encrypted communication.
The good news is that there is nothing extra to configure on the server side. We already take care of that part for you.
Protect Redis against brute force attacks
Your Redis instance is protected with a password, and Stackhero automatically generates a strong one by default. If you decide to change it, it is best to choose a very long and complex password.
Redis is extremely fast, and it can process a very high number of authentication attempts. In practice, that means an attacker could potentially try up to 150,000 password combinations per second.
To strengthen protection, we enforce a minimum password length of 16 characters, which represents approximately 4.5231285e+74 possible combinations. By default, Stackhero uses a 64-character password, which represents about 9.61963e+111 possible combinations.
For even stronger protection, you can also configure Stackhero firewall rules from the Firewall tab to allow connections only from your own IP addresses. This is one of the most effective ways to improve your overall security posture.