Redis Cloud
Pivotal Web Services End of Availability Announced
For more information, see Frequently Asked Questions.
Page last updated:
Redis Cloud is a fully-managed cloud service for hosting and running your Redis dataset in a highly-available and scalable manner, with predictable and stable top performance. You can quickly and easily get your apps up and running with Redis Cloud through its add-on for Cloud Foundry, just tell us how much memory you need and get started instantly with your first Redis database.
Redis Cloud offers true high-availability with its in-memory dataset replication and instant auto-failover mechanism, combined with its fast storage engine. You can easily import an existing dataset to any of your Redis Cloud databases, from your S3 account or from any other Redis server. Daily backups are performed automatically and in addition, you can backup your dataset manually at any given time. The service guarantees high performance, as if you were running the strongest cloud instances.
Managing Services
Creating a Redise Cloud Service Instance
Create a Redise Cloud service instance with the following command:
$ cf create-service rediscloud PLAN_NAME INSTANCE_NAME
where PLAN_NAME
is the desired plan’s name, and INSTANCE_NAME
is a name meaningful to you.
Binding Your Redise Cloud Service Instance
Bind your Redise Cloud service to your app, using the following command:
$ cf bind-service APP_NAME INSTANCE_NAME
Once your Redis Cloud service is bound to your app, the service credentials will be stored in the VCAP_SERVICES
environment variable in the following format:
{
"rediscloud": [
{
"name": "rediscloud-42",
"label": "rediscloud",
"plan": "20mb",
"credentials": {
"port"": "6379",
"hostname": "pub-redis-6379.us-east-1-2.3.ec2.redislabs.com",
"password": "your_redis_password"
}
}
]
}
For more information, see Delivering Service Credentials to an Application and VCAP_SERVICES Environment Variable.
Using Redis from Ruby
The redis-rb is a very stable and mature Redis client and is probably the easiest way to access Redis from Ruby.
Install redis-rb:
sudo gem install redis
Configuring Redis from Rails
For Rails 2.3.3 up to Rails 3.0, update the config/environment.rb
to include the redis gem:
config.gem 'redis'
For Rails 3.0 and above, update the Gemfile:
gem 'redis'
And then install the gem via Bundler:
bundle install
Lastly, create a new redis.rb
initializer in config/initializers/
and add the following code snippet:
rediscloud_service = JSON.parse(ENV['VCAP_SERVICES'])["rediscloud"]
credentials = rediscloud_service.first["credentials"]
$redis = Redis.new(:host => credentials["hostname"], :port => credentials["port"], :password => credentials["password"])
Configuring Redis on Sinatra
Add this code snippet to your configure block:
configure do
. . .
require 'redis'
rediscloud_service = JSON.parse(ENV['VCAP_SERVICES'])["rediscloud"]
credentials = rediscloud_service.first["credentials"]
$redis = Redis.new(:host => credentials.hostname, :port => credentials.port, :password => credentials.password)
. . .
end
Using Redis on Unicorn
No special setup is required when using Redise Cloud with a Unicorn server. For Rails apps on Unicorn, follow the instructions in the Configuring Redis from Rails section and for Sinatra apps on Unicorn see Configuring Redis on Sinatra section.
Testing (Ruby)
$redis.set("foo", "bar")
# => "OK"
$redis.get("foo")
# => "bar"
Using Redis from Java
Jedis is a blazingly small, sane and easy to use Redis java client. You can download the latest build from Github or use it as a maven dependency:
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.0.0</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
Configure the connection to your Redise Cloud service using the VCAP_SERVICES
environment variable and the following code snippet:
try {
String vcap_services = System.getenv("VCAP_SERVICES");
if (vcap_services != null && vcap_services.length() > 0) {
// parsing rediscloud credentials
JsonRootNode root = new JdomParser().parse(vcap_services);
JsonNode rediscloudNode = root.getNode("rediscloud");
JsonNode credentials = rediscloudNode.getNode(0).getNode("credentials");
JedisPool pool = new JedisPool(new JedisPoolConfig(),
credentials.getStringValue("hostname"),
Integer.parseInt(credentials.getNumberValue("port")),
Protocol.DEFAULT_TIMEOUT,
credentials.getStringValue("password"));
}
} catch (InvalidSyntaxException ex) {
// vcap_services could not be parsed.
}
Testing (Java)
jedis jedis = pool.getResource();
jedis.set("foo", "bar");
String value = jedis.get("foo");
// return the instance to the pool when you're done
pool.returnResource(jedis);
(example taken from Jedis docs).
Using Redis from Python
redis-py is the most commonly-used client for accessing Redis from Python.
Use pip to install it:
sudo pip install redis
Configure the connection to your Redise Cloud service using VCAP_SERVICES
environment variable and the following code snippet:
import os
import urlparse
import redis
import json
rediscloud_service = json.loads(os.environ['VCAP_SERVICES'])['rediscloud'][0]
credentials = rediscloud_service['credentials']
r = redis.Redis(host=credentials['hostname'], port=credentials['port'], password=credentials['password'])
Testing (Python)
>>> r.set('foo', 'bar')
True
>>> r.get('foo')
'bar'
Django
Redis can be used as the back-end cache for Django. To do so, install django-redis-cache:
pip install django-redis-cache
Next, configure your CACHES
in the settings.py
file:
import os
import urlparse
import json
rediscloud_service = json.loads(os.environ['VCAP_SERVICES'])['rediscloud'][0]
credentials = rediscloud_service['credentials']
CACHES = {
'default': {
'BACKEND': 'redis_cache.RedisCache',
'LOCATION': '%s:%s' % (credentials['hostname'], credentials['port']),
'OPTIONS': {
'PASSWORD': credentials['password'],
'DB': 0,
}
}
}
Testing (Django)
from django.core.cache import cache
cache.set("foo", "bar")
print cache.get("foo")
Using Redis from PHP
Predis is a flexible and feature-complete PHP client library for Redis.
Instructions for installing the Predis library can be found here.
Loading the library to your project should be straightforward:
<?php
// prepend a base path if Predis is not present in your "include_path".
require 'Predis/Autoloader.php';
Predis\Autoloader::register();
Configure the connection to your Redise Cloud service using VCAP_SERVICES
environment variable and the following code snippet:
// parsing rediscloud credentials
$vcap_services = getenv("VCAP_SERVICES");
$rediscloud_service = json_decode($vcap_services, true)["rediscloud"][0];
$credentials = $rediscloud_service["credentials"];
$redis = new Predis\Client(array(
'host' => $credentials["hostname"],
'port' => $credentials["port"],
'password' => $credentials["password"],
));
Testing (PHP)
$redis->set('foo', 'bar');
$value = $redis->get('foo');
Using Redis from Node.js
node_redis is a complete Redis client for node.js.
You can install it with:
npm install redis
Configure the connection to your Redise Cloud service using VCAP_SERVICES
environment variable and the following code snippet:
// parsing rediscloud credentials
var vcap_services = process.env.VCAP_SERVICES;
var rediscloud_service = JSON.parse(vcap_services)["rediscloud"][0]
var credentials = rediscloud_service.credentials;
var redis = require('redis');
var client = redis.createClient(credentials.port, credentials.hostname, {no_ready_check: true});
client.auth(credentials.password);
Testing (Node.js)
client.set('foo', 'bar');
client.get('foo', function (err, reply) {
console.log(reply.toString()); // Will print `bar`
});
Dashboard
Our dashboard presents all performance and usage metrics of your Redis Cloud service on a single screen, as shown below:
To access your Redis Cloud dashboard, click the ‘Manage’ button next to the
Redis Cloud service in Apps Manager.
You can find your dashboard under the MY DATABASES
menu.
Support
Any Redis Cloud support issues or product feedbacks are welcome via email at support@redislabs.com. Please make sure you are familiar with the CloudFoundry method of contacting service providers for support.