RedisGreen
Last updated June 08, 2022
Table of Contents
Creating a RedisGreen server
You can use the Heroku CLI to add RedisGreen to your app:
$ heroku addons:create redisgreen:basic
Adding redisgreen:basic to fancy-slinky-2001... done, v24 ($169/mo)
Basic Redis server successfully provisioned.
Use `heroku addons:docs redisgreen:basic` to view documentation
Once your RedisGreen server has been built, your app will have access to a “REDISGREEN_URL” environment variable that contains the Redis URI for your Redis server. You can also view the RedisGreen environment variable using the Heroku CLI:
$ heroku config | grep REDISGREEN
REDISGREEN_URL: redis://rg:gnysfn55t65g72ntd4g0a6h8ea91ca9v@smart-panda.redisgreen.net:10042
RedisGreen Dashboard
The RedisGreen dashboard provides graphs, alerts, diagnostic information, and more. Access the RedisGreen dashboard through your app’s Heroku Dashboard page or through the Heroku CLI:
$ heroku addons:open redisgreen
Using Redis with Ruby
Add the redis and hiredis gems to your Gemfile and run bundle install
to
install them:
gem 'redis'
gem 'hiredis'
For Rails apps, create an initializer at config/initializers/redis.rb
to create a global Redis connection when your app loads:
$redis = Redis.new(url: ENV["REDISGREEN_URL"], driver: :hiredis)
For all non-Rails projects, you can use the above code wherever it makes the most sense. For example, in Sinatra apps, you would put the above code in the “configure” block:
require 'redis'
configure :production do
uri = URI.parse(ENV["REDISGREEN_URL"])
$redis = Redis.new(url: ENV["REDISGREEN_URL"], driver: :hiredis)
end
configure :development, :test do
$redis = Redis.new
end
Using Redis with Python
Install the “redis” package:
% pip install redis
And create your Redis connection with:
import os, redis
redis = redis.from_url(os.getenv("REDISGREEN_URL"))
To use Redis as a cache backend for your Django app with django-redis:
CACHES = {
"default": {
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": os.getenv("REDISGREEN_URL"),
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
}
}
}
To use RedisGreen as your session store, you’ll also need to update your Django session engine settings:
SESSION_ENGINE = "django.contrib.sessions.backends.cache"
SESSION_CACHE_ALIAS = "default"
Using Redis with Node.js
Install the “redis” package using npm:
$ npm install redis
And then run npm install
to install the package locally. You can then
create your Redis connection with:
var redis = require("redis");
var client = redis.createClient(process.env.REDISGREEN_URL);
Using Redis with PHP
We recommend the predis
library. Add the library to your composer.json
file:
"require": {
...
"predis/predis": "1.0.3",
...
}
And connect by using the REDISGREEN_URL
environment variable:
$redis = new Predis\Client(getenv('REDISGREEN_URL'));
Custom Configuration
If you need any configuration, just hit the “Support” button in the RedisGreen dashboard or email us at support@redisgreen.net and we’ll work with you to implement the best configuration for your particular needs.
Rotating Credentials
Rotating credentials with RedisGreen is simple, just hit the “Support” link in the RedisGreen dashboard and request a credential rotation. Depending on your requirements, RedisGreen can provide a hot standby database with new credentials which you can migrate to on your own, or RedisGreen can push a new REDIS_URL
variable to your application, restarting your dynos with the new credentials.
Removing RedisGreen
RedisGreen can be removed from your app via the Heroku CLI:
$ heroku addons:destroy redisgreen
! WARNING: Destructive Action
! This command will affect the app: fancy-slinky-2001
! To proceed, type "fancy-slinky-2001" or re-run this command with --confirm fancy-slinky-2001
> fancy-slinky-2001
Removing redisgreen:basic from fancy-slinky-2001... done, v25 ($169/mo)
Additional Support
Use the “Support” button in the RedisGreen dashboard or email us at support@redisgreen.net to get help with any aspect of your RedisGreen server, including custom configurations.