Scalingo for Redis®
Scalingo for Redis® is the official Redis®* 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 Scalingo for Redis® to Your app
You can add the Scalingo for 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
- Go to your app on Scalingo Dashboard
- Click on Addons tab
- Select the addon you want to add
- In the dialog select the database plan you need
- Validate your choice
Through the Command-Line Interface
$ scalingo --app my-app addons-add redis redis-starter-1024
-----> 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 redis-starter-1024
Scalingo for Redis® database plan.
To find out what other plans are available:
$ scalingo addons-plans redis
Scalingo for Redis® Cluster Setup
If using a Business plan for your Scalingo for Redis® addon, we setup a Redis® cluster. This cluster has the following configuration:
- multiple Redis® nodes in a private network: the amount of memory per node depends on the plan,
- a couple of HAProxy as entrypoint to the Redis® private network: one is the leader and the other is just here as a backup in case of failing leader.
- three Redis® sentinels to initiate the election of a new leader if the current leader fails.
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
- Go to your app on Scalingo Dashboard
- Click on Environment tab
-
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:YANs3y07m5_KJC2MSDGebh8tx1lliFWh2Yb239zVqGQvbElWDjIN7QWspVH92Ul8@my-app-3030.redis.a.osc-fr1.scalingo-dbs.com: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.
Force TLS Connections
If you want to enforce TLS connections to your database so that TLS is not only available, but mandatory:
- From your web browser, open your database dashboard
- Select the Settings tab
- In the Settings submenu, select Internet Access
- Locate the Force TLS connections block
- Click the Enable button
Once this option is activated, the database denies any non-TLS connection. Consequently, your application must be configured to use TLS when connecting to the database. Please note that while we strongly advise to use TLS, it remains an option, meaning that you can still access your database without it if needed.
Scalingo for Redis® Configuration
Number of Databases
Each Redis® instance can use 5 databases (numbered from 0, the default DB, to 4).
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.
Managing it from the Database Dashboard
- From your web browser, open your database dashboard
- Select the Settings tab
- In the Settings submenu, select Configuration
- Locate the RDB Persistence block
- Click the Enable button
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.
Managing it from the Database Dashboard
- From your web browser, open your database dashboard
- Select the Settings tab
- In the Settings submenu, select Configuration
- Locate the AOF Persistence block
- Click the Enable button
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 atallkeys-lru
, which means ‘Least Recently Used’ keys will be evicted first if themaxmemory
amount is reached.
Managing it from the Database Dashboard
- From your web browser, open your database dashboard
- Select the Settings tab
- In the Settings submenu, select Configuration
- Locate the Cache Mode block
- Click the Enable button
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
- Go to your app on Scalingo Dashboard
- Click on Addons tab
- Select the addon you want to change
- In the dialog select the plan you want to upgrade/downgrade to
- Validate your choice
From the Database Dashboard
- From your web browser, open your database dashboard
- Click the Settings tab
- In General, select Change plan
- Select the new plan
- Click the Finish button
- Validate by clicking the Confirm plan change button
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 ad-0f1ab3e1-e97d-4f33-9168-4956379731a4 redis-starter-2048
In this example, ad-0f1ab3e1-e97d-4f33-9168-4956379731a4
is the ID of the addon, and redis-starter-2048
is the plan we want to upgrade to.
To find out the addon ID:
$ scalingo --app my-app addons
+--------+-----------------------------------------+---------------------+
| ADDON | ID | PLAN |
+--------+-----------------------------------------+---------------------+
| Redis | ad-0f1ab3e1-e97d-4f33-9168-4956379731a4 | redis-business-256 |
+--------+-----------------------------------------+---------------------+
Database Dashboard
The Scalingo for 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 take some time to study it and test it thoroughly before making it available. Upgrading to this new version is still your choice. We don’t do it automatically.
Your database needs to be upgraded to the latest minor version before having access to the next major version. For instance, let’s imagine that your version is 2.3.x
and you want to upgrade to 3.1.x
. If there is a 2.5.x
version available, you first need to upgrade your database to the 2.5.x
version before upgrading to the 3.1.x
version.
During the upgrade, a downtime can unfortunately happen, depending on the Plan you are using and the upgrade:
- Starter Plans: In all cases, we have to stop the node to upgrade it, causing an inevitable downtime.
- Business Plans: We are able to achieve zero-downtime upgrade of minor version. In the case of major version upgrade, we need to completely stop the nodes, hence causing an inevitable downtime. In both cases, once the operation is finished, the application is restarted.
Using the Database Dashboard
- From your web browser, open your database dashboard
- Select the Settings tab
- In the Settings submenu, select the General tab
- Locate the Database Version block
- If an upgrade is available, a button allows you to trigger the upgrade
- Click the button to launch the upgrade process
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. |
Database Users
Scalingo does not leverage yet the ACL feature introduced in Redis® 6. Hence Scalingo Redis® databases have a single default user with a password generated by Scalingo. The list of ACL of this default user are:
user default on <password> ~* &* +@all
It is not possible to create another user on a Redis® database.
Backups
If your database is in a paid plan (i.e. it’s not “free plan”), we’ll automatically make periodic backups of your database on a daily basis, at around 1:00 AM Central European Time (CET or UTC+0100). The time of your daily backup is configurable via the web dashboard of your database or using the CLI. The scheduled date is not strongly enforced: it might get delayed depending on the load on our infrastructure.
Using the Database Dashboard
- From your web browser, open your database dashboard
- Click the Backups tab
- Locate the Backup schedule block
- Click the Schedule button
- Make sure to check the I want to enable scheduled backups checkbox
- Pick an hour (timezone is UTC)
- Validate by clicking the Update button
Using the Command Line
- Make sure you have correctly setup the Scalingo command line tool
- Configure the time of backup:
- By setting an hour:
scalingo --app my-app --addon [YOUR ADDON KIND] backups-config --schedule-at 3
In this example, we ask the platform to create the backups at ~03:00. Note: The timezone used is the local timezone of the machine running the command.
- By setting an hour and a timezone:
scalingo --app my-app --addon [YOUR ADDON KIND] backups-config --schedule-at "4:00 UTC"
In this example, we ask the platform to create the backup at ~04:00 UTC. The output should look like this:
-----> Periodic backups will be done daily at 6:00 CET
- By setting an hour:
Retention Policy for Daily Backups
We keep a limited amount of backups depending on your database plan. A daily backup is retained for the last 7 days. That means that 7 backups will exist, one for each of the last 7 days. A weekly backup means that only one backup is saved over a 7 days period. A monthly backup means that only 1 backup is saved over the course of a month.
Plan | Weekly Backups Retained | Monthly Backup Retained |
---|---|---|
Sandbox/Free | N/A | N/A |
Starter | 4 weeks | 0 months |
Business | 8 weeks | 12 months |
Retention Policy for Manual Backups
You can also manually trigger a backup for your database at any time you want. The number of manual backups that you can retain is limited by your plan:
Plan | Backups Retained |
---|---|
Sandbox/Free | N/A |
Starter | 10 |
Business | 50 |
In case a database is removed from an application, the retention policy remains untouched: backups are not instantly deleted.
Creating a Manual Backup
Using the Database Dashboard
- From your web browser, open your database dashboard
- Click the Backups tab
- Locate the Backup Settings block
- Click the Make Manual Backup button
- Locate the Backups block
- Click the Trigger manual backup button
Using the Command Line
- Make sure you have correctly setup the Scalingo command line tool
- Ask the platform to backup the database:
scalingo --app my-app --addon [YOUR ADDON KIND] backups-create
After a while, the output should look like this:
-----> Backup successfully finished
Downloading a Backup
Using the Database Dashboard
- From your web browser, open your database dashboard
- Click the Backups tab
- Locate the Backups block
- Locate the Periodic backup you are interested in
- Click the corresponding Download button
Using the Command Line
- Make sure you have correctly setup the Scalingo command line tool
- Run the following command(s):
- To download the latest backup available:
scalingo --app my-app --addon redis backups-download
The output should look like this:
-----> Selected the most recent successful backup 139.37 KiB / 139.37 KiB [----------------------------------] 100.00% ? p/s ===> 20231207000608_my_app_4553.tar.gz
The backup is downloaded in your current working directory.
- To download a specific backup:
- List the backups available for this database addon:
scalingo --app my-app --addon redis backups
The output should look like this:
+--------------------------+--------------------------------+--------+--------+ | ID | CREATED AT | SIZE | STATUS | +--------------------------+--------------------------------+--------+--------+ | 65710b0a99c3cd23d455edee | Thu, 07 Dec 2023 01:00:10 CET | 143 kB | done | | 656fb98b99c3cd23d455d4e7 | Wed, 06 Dec 2023 01:00:11 CET | 143 kB | done | | 656e680a99c3cd23d455c1f0 | Tue, 05 Dec 2023 01:00:10 CET | 143 kB | done | ...
- Locate the
ID
of the backup you want to download - Download the backup:
scalingo --app my-app --addon redis backups-download --backup <backup_ID>
The output should look like this:
79.10 KiB / 79.10 KiB [---------------------------------] 100.00% ? p/s ===> 20230305000044_my_app_4553.tar.gz
The backup is downloaded in your current working directory.
- List the backups available for this database addon:
- To download the latest backup available:
*Redis® is a registered trademark of Redis® Ltd. Any rights therein are reserved to Redis® Ltd. Any use by Scalingo is for referential purposes only and does not indicate any sponsorship, endorsement or affiliation between Redis® and Scalingo.