Add Redis to Your Application

Redis is an open source, advanced key-value store. It is often referred to as a data structure server because keys can contain strings, hashes, lists, sets, and sorted sets.

This page describes getting Redis working on your Engine Yard Cloud application.

Install Redis on a utility instance

To install Redis you'll need to use a custom Chef recipe; for more information about custom Chef recipes, see Custom Chef recipes.

Note: You should only have one Redis install per environment. Engine Yard does not recommend installing Redis on your application instances because it can cause complications. For example, if you have more than one app instances, installing Redis on those instances can result in multiple Redis versions on your app servers. If you install it only on your application master, it will likely get overloaded.

Here is a procedure for adding Redis to a utility instance named “redis”. You’ll need to adjust this procedure for your specific environment.

To install Redis on a utility instance

  1. Download the ey-cloud-recipes to your local computer.

    $ git clone 
  2. Uncomment include_recipe "redis" from the main cookbook (main/recipes/default.rb).

  3. Add a utility instance named “redis” to your application.

  4. If not already installed, install the engineyard gem

    $ gem install engineyard
  5. Upload and apply the recipes to your environment:

    $ ey recipes upload -e <environment_name> 
    $ ey recipes apply -e <environment_name>

To connect to Redis on the utility instance from your Rails application

Repeat steps 2 and 4 in the above instructions, but this time uncomment include_recipe "redis-yml". The Apply run will then write out a redis.yml configuration file. You can then connect to Redis in an initializer or environment file using the following:

# Load the redis.yml configuration file 
redis_config = YAML.load_file(Rails.root + 'config/redis.yml')[Rails.env]

# Connect to Redis using the redis_config host and port
if redis_config
$redis = redis_config['host'], port: redis_config['port'])

Install the Redis gem

First, you need to bundle the Redis gem into your application.

To add Redis to your application

  1. Add the Redis gem to your gemfile.
    gem ‘redis’
  2. Install the Redis gem using bundler from your development machine.
    bundle install
  3. Deploy your application.

Update the Redis version

To upgrade to a newer version of Redis pull the latest changes to the Redis custom Chef recipe into your fork from upstream, or edit the install version within your existing recipe. Upload and apply this recipe update; to complete the upgrade you will need to restart Redis (we do not recommend adding the restart to the chef Recipe).

To find out your Redis version

  1. Via SSH, connect to the Utility instance that runs your Redis service.

  2. Type:

  3. At the Redis prompt, type:

    redis> info

    The response shows the version number on the first line:

  4. If your version is older that the recommended version (see Engine Yard Technology Stack), follow the procedure below to update the Redis version.

To update Redis

  1. Via SSH, connect to the Utility instance that runs your Redis service.

  2. Type:

    sudo monit restart redis

Things to do with Redis

You can use Redis:

More information

For more information about... See...
Resque and Redis                                                                                    Configure and deploy Resque.                                                                        
SSHing into an instance Connect to your instance via SSH.
Using Redis with Unicorn Customize Unicorn.

If you have feedback or questions about this page, add a comment below. If you need help, submit a ticket with Engine Yard Support.


Article is closed for comments.