Redis is an open source, advanced key-value store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets and sorted sets. More information can be found at redis.io
openredis is accessible via an API and has supported client libraries for C, C#, C++, Clojure, Dart, Erlang, Fancy, Go, Haskell, Io, Java, Lua, Node.js, Objective C, Perl, PHP, Python, Ruby, Scala, Smalltalk and Tcl.
This is how your dashboard will look like once the add-on is integrated:
If you haven't subscribed already, please check our guide to subscribing.
After provisioning the add-on it’s necessary to locally replicate the config vars so your development environment can operate against the service.
Use Foreman to reliably configure and run
the process formation specified in your app’s Procfile.
Foreman reads configuration variables from an .env file. Use the
following command to add the OPENREDIS_URL
values retrieved from
heroku config to .env
.
$ echo 'OPENREDIS_URL=redis://...' >> .env
$ more .env
Credentials and other sensitive configuration values should not be committed to source-control. In Git exclude the .env file with: `echo .env >> .gitignore`.
Using Redis from Ruby is very straightforward. Start by installing the Redis client:
:::term
$ gem install redis
Now, create a client and connect it to Redis:
:::ruby
$redis = Redis.connect :url => ENV["OPENREDIS_URL"]
:::ruby
require "redis"
class MyApp < Sinatra::Base
configure do
$redis = Redis.connect :url => ENV["OPENREDIS_URL"]
end
end
Ruby on Rails applications will need to add the following entry into
their Gemfile
specifying the openredis client library.
:::ruby
gem "redis"
Update application dependencies with bundler.
:::term
$ bundle install
You can connect to Redis by using the OPENREDIS_URL
:
:::ruby
$redis = Redis.connect :url => ENV["OPENREDIS_URL"]
Install redis-py:
:::term
$ sudo pip install redis # or sudo easy_install redis
Then connect to Redis:
:::python
import redis
client = redis.from_url(ENV["OPENREDIS_URL"])
Install node_redis:
:::term
$ npm install redis
Then use the following snippet to connect to Redis:
:::javascript
var url = require("url").parse(process.env.OPENREDIS_URL);
var redis = require("redis").createClient(url.port, url.hostname);
redis.auth(url.auth.split(":")[1]);
Install Jedis by following the author's instructions.
Then use the following snippet to connect to Redis:
:::java
URI url = new URI(System.getenv("OPENREDIS_URL"));
JedisPool pool = new JedisPool(new JedisPoolConfig(),
url.getHost(),
url.getPort(),
Protocol.DEFAULT_TIMEOUT,
url.getUserInfo().split(":", 2)[1]);
When developing locally it is best to turn off the integration with
openredis to minimize dependencies on remote services. You can use a
local Redis server, and point OPENREDIS_URL
to localhost and the
appropriate port.
For example:
:::ruby
ENV["OPENREDIS_URL"] = "redis://localhost:6379"
$redis = Redis.connect(:url => ENV["OPENREDIS_URL"])
Important note: Starting November 14, 2012, all plans provisioned in AWS are accessible only from within the AWS network.
Make sure you can connect with redis-cli
. If that works, check
you are getting the credentials right in your application. For
support questions, you can find us at #openredis on Freenode, mention
@openredis on Twitter, or simply
email us at info@openredis.com.
Additional resources are available at: