Skip Navigation
Show nav
Heroku Dev Center
  • Get Started
  • Documentation
  • Changelog
  • Search
  • Get Started
    • Node.js
    • Ruby on Rails
    • Ruby
    • Python
    • Java
    • PHP
    • Go
    • Scala
    • Clojure
  • Documentation
  • Changelog
  • More
    Additional Resources
    • Home
    • Elements
    • Products
    • Pricing
    • Careers
    • Help
    • Status
    • Events
    • Podcasts
    • Compliance Center
    Heroku Blog

    Heroku Blog

    Find out what's new with Heroku on our blog.

    Visit Blog
  • Log inorSign up
View categories

Categories

  • Heroku Architecture
    • Dynos (app containers)
    • Stacks (operating system images)
    • Networking & DNS
    • Platform Policies
    • Platform Principles
  • Command Line
  • Deployment
    • Deploying with Git
    • Deploying with Docker
    • Deployment Integrations
  • Continuous Delivery
    • Continuous Integration
  • Language Support
    • Node.js
    • Ruby
      • Working with Bundler
      • Rails Support
    • Python
      • Working with Django
      • Background Jobs in Python
    • Java
      • Working with Maven
      • Java Database Operations
      • Working with the Play Framework
      • Working with Spring Boot
      • Java Advanced Topics
    • PHP
    • Go
      • Go Dependency Management
    • Scala
    • Clojure
  • Databases & Data Management
    • Heroku Postgres
      • Postgres Basics
      • Postgres Performance
      • Postgres Data Transfer & Preservation
      • Postgres Availability
      • Postgres Special Topics
    • Heroku Redis
    • Apache Kafka on Heroku
    • Other Data Stores
  • Monitoring & Metrics
    • Logging
  • App Performance
  • Add-ons
    • All Add-ons
  • Collaboration
  • Security
    • App Security
    • Identities & Authentication
    • Compliance
  • Heroku Enterprise
    • Private Spaces
      • Infrastructure Networking
    • Enterprise Accounts
    • Enterprise Teams
    • Heroku Connect (Salesforce sync)
    • Single Sign-on (SSO)
  • Patterns & Best Practices
  • Extending Heroku
    • Platform API
    • App Webhooks
    • Heroku Labs
    • Building Add-ons
      • Add-on Development Tasks
      • Add-on APIs
      • Add-on Guidelines & Requirements
    • Building CLI Plugins
    • Developing Buildpacks
    • Dev Center
  • Accounts & Billing
  • Troubleshooting & Support
  • Add-ons
  • All Add-ons
  • Stackhero for Redis
Stackhero for Redis

This add-on is operated by Stackhero

Redis on dedicated instances, up-to-date versions and attractive pricing.

Stackhero for Redis

Last updated January 31, 2021

The Stackhero for Redis add-on is currently in beta.

Table of Contents

  • Provisioning the add-on
  • Local setup
  • Using with Java
  • Using with Ruby
  • Using with Python
  • Using with PHP
  • Using with Go
  • Using with Node.js
  • Dashboard and web UI (Redis Commander)
  • Set eviction policy
  • Upgrading your plan
  • Removing the add-on
  • Support
  • Additional resources

Stackhero for Redis provides a managed Redis instance running on a fully dedicated instance.

With your Stackhero for Redis add-on you will get:

  • A private instance (dedicated VM)
  • A dedicated public IP (v4)
  • TLS encryption (aka SSL)
  • An automatic backup every 24 hours
  • A graphical web UI (Redis Commander)
  • One click to update to new Redis versions

All Redis clients can connect to Stackhero for Redis and there is a Redis client library for almost every platform out there, including Ruby, Node.js, Java, Python, Clojure, and Erlang.

When you will choose a Redis client library, prefer one that supports TLS encryption (aka SSL) for best security. We strongly discourage you to use Redis without TLS support unless you know exactly what you are doing.

Provisioning the add-on

Stackhero for Redis can be attached to a Heroku application via the CLI:

A list of all plans available can be found here.

$ heroku addons:create stackhero-redis --app <your app name>
-----> Adding stackhero-redis to sharp-mountain-4005... done, v18 (free)

After you provision Stackhero for Redis, the STACKHERO_REDIS_URL_TLS and STACKHERO_REDIS_URL_CLEAR config vars are available in your app’s configuration. They contain the URLs to your Redis instance as its credentials.

  • STACKHERO_REDIS_URL_TLS is the URL to your Redis instance with TLS encryption. This is the recommended way to connect to your Redis instance.
  • STACKHERO_REDIS_URL_CLEAR is the URL to your Redis instance with no encryption (clear).

You can see the content of those vars via the heroku config:get command:

$ heroku config:get STACKHERO_REDIS_URL_TLS
rediss://user:password@domain:port

After you install Stackhero for Redis, your application should be configured to fully integrate with the add-on.

Local setup

After you provision the add-on, it’s necessary to locally replicate its config vars so your development environment can operate against the service.

Use the Heroku Local command-line tool to configure, run and manage process types specified in your app’s Procfile. Heroku Local reads configuration variables from a .env file. To view all of your app’s config vars, type heroku config. Use the following command for each value that you want to add to your .env file:

$ heroku config:get STACKHERO_REDIS_URL_TLS -s  >> .env
$ heroku config:get STACKHERO_REDIS_URL_CLEAR -s  >> .env

Credentials and other sensitive configuration values should not be committed to source-control. In Git exclude the .env file with: echo .env >> .gitignore.

For more information, see the Heroku Local article.

Using with Java

You can use the environment variable STACKHERO_REDIS_URL_TLS to connect to Redis.

Here is an example of a connection using Jedis:

private static Jedis getConnection() throws URISyntaxException {
  URI redisURI = new URI(System.getenv("STACKHERO_REDIS_URL_TLS"));
  Jedis jedis = new Jedis(redisURI);
  return jedis;
}

You will find more information on the official Jedis repository and the official wiki.

In a multithreaded environment, like a webserver, you should use Jedis Pool:

public static JedisPool getPool() {
  URI redisURI = new URI(System.getenv("STACKHERO_REDIS_URL_TLS"));
  JedisPoolConfig poolConfig = new JedisPoolConfig();
  poolConfig.setMaxTotal(10);
  poolConfig.setMaxIdle(5);
  poolConfig.setMinIdle(1);
  poolConfig.setTestOnBorrow(true);
  poolConfig.setTestOnReturn(true);
  poolConfig.setTestWhileIdle(true);
  JedisPool pool = new JedisPool(poolConfig, redisURI);
  return pool;
}

See the official wiki for more information.

Using with Ruby

Install the Redis gem:

$ gem 'redis'
$ bundle install

You can find more information on the official Ruby Redis repository.

With Rails, you have to create the initializer file config/initializers/redis.rb like this:

$redis = Redis.new(url: ENV["STACKHERO_REDIS_URL_TLS"])

Using with Python

Install the Redis package:

$ pip install redis
$ pip freeze > requirements.txt
import os
import redis

r = redis.from_url(os.environ.get("STACKHERO_REDIS_URL_TLS"))

You will get more information from the official Python redis package documentation.

Using with PHP

Retrieve the URL with getenv('STACKHERO_REDIS_URL_TLS') and pass it to your preferred Redis client library.

Using with Go

First install the go-redis package:

$ go get github.com/go-redis/redis/v8

Then, import it in your code:

import "github.com/gomodule/redigo/redis"

Finally, connect to the Redis server using the STACKHERO_REDIS_URL_TLS variable:

opt, err := redis.ParseURL(os.Getenv("STACKHERO_REDIS_URL_TLS"))
if err != nil {
    panic(err)
}

rdb := redis.NewClient(opt)

You will find more information on the official go-redis repository

Using with Node.js

We recommend using ioredis.

Install the ioredis package:

$ npm install ioredis
const Ioredis = require('ioredis');

(async () => {

  const redis = new Ioredis(process.env.STACKHERO_REDIS_URL_TLS);

  // Set key "stackhero-example-key" to "abcd"
  await redis.set('stackhero-example-key', 'abcd');

  // Get key "stackhero-example-key"
  const value = await redis.get('stackhero-example-key');
  console.log(`Key "stackhero-example-key" has value "${value}"`);

  // Finally delete key "stackhero-example-key"
  await redis.del('stackhero-example-key');

})().catch(error => {
  console.error('An error occurred!', error);
});

You will find a lot of other examples on the official ioredis repository.

Dashboard and web UI (Redis Commander)

Stackhero dashboard allows you to see your instance usage, restart it, and apply updates. It also gives you the ability to access the web UI to consult your Redis data directly in a graphical way.

You can access the dashboard via the CLI:

$ heroku addons:open stackhero-redis
Opening stackhero-redis for sharp-mountain-4005

or by visiting the Heroku Dashboard and selecting the application in question. Select Stackhero for Redis from the Add-ons menu.

Set eviction policy

Yon can define how Redis will react when you consume more memory than available on your plan.

To do this, connect to your Stackhero dashboard (see above), select your Redis service, then click on Configure and set the Eviction policy setting.

Upgrading your plan

You cannot downgrade an existing add-on.

 

Application owners should carefully manage the migration timing to ensure proper application function during the migration process.

Use the heroku addons:upgrade command to migrate to a new plan.

$ heroku addons:upgrade stackhero-redis:newplan
-----> Upgrading stackhero-redis:newplan to sharp-mountain-4005... done, v18 ($49/mo)
       Your plan has been updated to: stackhero-redis:newplan

Removing the add-on

You can remove Stackhero for Redis via the CLI:

This will destroy all associated data and cannot be undone!

$ heroku addons:destroy stackhero-redis
-----> Removing stackhero-redis from sharp-mountain-4005... done, v20 (free)

Support

All Stackhero for Redis support and runtime issues should be submitted via one of the Heroku Support channels. We recommend adding support@stackhero.io in copy for urgent issues.

Additional resources

  • Stackhero for Redis - Getting started

Keep reading

  • All Add-ons

Feedback

Log in to submit feedback.

Ziggeo StatusHub

Information & Support

  • Getting Started
  • Documentation
  • Changelog
  • Compliance Center
  • Training & Education
  • Blog
  • Podcasts
  • Support Channels
  • Status

Language Reference

  • Node.js
  • Ruby
  • Java
  • PHP
  • Python
  • Go
  • Scala
  • Clojure

Other Resources

  • Careers
  • Elements
  • Products
  • Pricing

Subscribe to our monthly newsletter

Your email address:

  • RSS
    • Dev Center Articles
    • Dev Center Changelog
    • Heroku Blog
    • Heroku News Blog
    • Heroku Engineering Blog
  • Heroku Podcasts
  • Twitter
    • Dev Center Articles
    • Dev Center Changelog
    • Heroku
    • Heroku Status
  • Facebook
  • Instagram
  • Github
  • LinkedIn
  • YouTube
Heroku is acompany

 © Salesforce.com

  • heroku.com
  • Terms of Service
  • Privacy
  • Cookies