Resources for Developers

Redis

Redis is the official addon provided by Scalingo, details on the available plans can be found here. This addon gives your app instant access to a Redis database running in its own Docker container.

Adding Redis to your app

You can add the Redis addon through the dashboard or through the command line interface. The capacity of your database is elastic, you will be able to upgrade it later.

Through the Dashboard

  1. Go to your app on Scalingo Dashboard
  2. Click on Addons tab
  3. Select the addon you want to add
  4. In the dialog select the database plan you need
  5. Validate your choice

Through the command-line interface

$ scalingo --app my-app addons-add redis 1g

-----> Addon redis has been provisionned
       ID: my-app-3030
       Modified variables: [REDIS_URL SCALINGO_REDIS_URL]
       Message from addon provider: Database successfully created

This command will provision the application my-app with a 1g Redis database plan.

To find out what other plans are available:

$ scalingo addons-plans redis

Getting your connection URI

Once the addon is provisioned, 2 environment variables are added to your app: SCALINGO_REDIS_URL and REDIS_URL. REDIS_URL is an alias to SCALINGO_REDIS_URL for the convenience of some libraries such as the Ruby gem sidekiq, but using SCALINGO_REDIS_URL is preferred in most cases. To find out how to use it in your code please refer to Application environment.

In most cases, you can pass the variable directly to the client library you are using in your code. But sometimes the library requires a specific URI format, you’ll need to add a little bit of code to suit the library.

You can get environment variables from the dashboard or the command line interface.

From the Dashboard

  1. Go to your app on Scalingo Dashboard
  2. Click on Environment tab
  3. SCALINGO_REDIS_URL is displayed

From the command-line interface

$ scalingo --app my-app env | grep REDIS

REDIS_URL=$SCALINGO_REDIS_URL
SCALINGO_REDIS_URL=redis://my-app-3030:l2ebPNwe-IWVJmV8OlLX@my-app-3030.redis.dbs.appsdeck.eu:30996

Remote access your database

If you need to access your database from other places than your app please follow the Access your database guide.

Redis configuration

Number of databases

Each Redis instance can use 6 databases (numbered from 0, the default DB, to 5)

Idle connections timeout

Redis configuration:

timeout 150

It means that if a connection has not been used during 150 seconds, it will be automatically closed by Redis. This is done to avoid accumulating staled connections. You must ensure that your application code handles gracefully potential timeouts in Redis connections.

Persistence mode

Redis does not write all the operations requested by users on disk instantly, the write operations are done asynchronously by following different rules. There are two persistence modes: snapshot and strong persistence. They both represent a different trade-off in terms of performance and reliability. As such, you must take great care in your Redis persistence mode settings.

Snapshot persistence aka RDB

The first, and default mode, is the snapshot mode (also called RDB). It provides a compromise between performance and persistence. Data are saved to disk periodically, according to a defined number of write operations, asynchronously:

  • Save to disk every 15 minutes if at least 1 operation has been done
  • Save to disk every 5 minutes if at least 10 operations have been done
  • Save to disk every minute if at least 10,000 operations have been done

It means that in the scope of an incident, recent data are lost.

Strong persistence aka AOF

The second mode provides Redis with the highest level of persistence (also called AOF). Any command impacting the dataset will be saved synchronously in a file. In case of incident, Redis replays the logged operations to reconstruct the database dataset.

The typical use case is when using Redis as a key-value store. We can imagine the comments on a blog post page being stored in a Redis list. Losing comments because of an unexpected Redis restart is not acceptable and activating AOF mode sounds like a good idea.

Cache Mode

The last available configuration is related to how long data are stored in Redis. When cache mode is activated and the memory is full, Redis will automatically drop the less recently used data to free up memory for most recent data. Be cautious as any data can be deleted.

The typical use case is Scalingo’s homepage and blog. It uses Redis as a cache for HTML fragments. In such case, we can afford using the oldest data stored in Redis, and re-compute them if needed.

This feature uses two settings of Redis:

  • maxmemory: Amount of data Redis accepts before dropping some of them. It is set at the value of the memory available of the database plan you have chosen.
  • maxmemory-policy: Set at allkeys-lru, which means ‘Least Recently Used’ keys will be evicted first if the maxmemory amount is reached.

Changing plans

You can upgrade or downgrade your database plan whenever you need it. This operation happens instantly thanks to Docker containers and no manual input is required. When you change the plan, your database will be stopped then restarted on a new host with new parameters of the chosen plan. During the operation the connection is dropped between your app and the database. Finally, after the operation is successful, the related app will be restarted.

From the Dashboard

  1. Go to your app on Scalingo Dashboard
  2. Click on Addons tab
  3. Select the addon you want to change
  4. In the dialog select the plan you want to upgrade/downgrade to
  5. Validate your choice

From the command-line interface

To upgrade or downgrade your addon the sub-command is the same: addons-upgrade.

$ scalingo --app my-app addons-upgrade my-app-3030 2g

In this example, my-app-3030 is the ID of the addon, and 2g is the plan we want to upgrade to.

To find out the addon ID:

$ scalingo --app my-app addons

+----------------+------------------+------+
|      ADDON     |        ID        | PLAN |
+----------------+------------------+------+
| Redis | my-app-3030      |   1g |
+----------------+------------------+------+

Database dashboard

The Redis dashboard is the central place for administrative tasks such as:

  • Monitor database and system stats
  • Upgrade the database engine version
  • Activate database specific features
  • Manage database users
  • Manage backups

Database Upgrade

When the database vendor releases a new version of your database engine, we will try to provide it as soon as possible. You will have the choice to upgrade your database with one click through your database dashboard.

This operation is similar to changing your database plan; your database will be stopped and restarted with new database environment. Thanks to Docker containers this happens seamlessly and quickly without manual action. When this operation finishes, your application will be restarted.

Container Stats

CPU usage Current CPU usage.
Memory usage Display the current, hightest and free memory. Highest is the maximum memory recorded since database restarted.
Swap usage Display the current, hightest and free swap. Highest is the maximum swap recorded since database restarted.

Database Stats

Database on disk size Effective physical space used.

Backups

If your database is in a paid plan (i.e. it’s not “free plan”), we’ll make automated backups of your database on a daily basis, at around 1 AM Central European Time (CET or UTC+0100). However, we don’t keep those backups forever. The following rules are applied for backups storing:

  • Everyday for the past 30 days (1 month)
  • One per week during the 2nd and 3rd months
  • One per month during the 4th, 5th and 6th months

Download automated backups

Automated backups are listed in the database specific dashboard.

  1. Go to your app on Scalingo Dashboard
  2. Click on Addons tab
  3. Click Link to dashboard which will take you to the Redis dashboard
  4. Click on Backups tab
  5. Download the backup you want

mode_edit Suggest edits