Create a Redis database on Heroku
Heroku is a cloud Platform as a Service (PaaS) supporting multiple programming languages that is used as a web application deployment model. Heroku lets the developer build, run and scale applications in a similar manner across all the languages(Java, Node.js, Scala, Clojure, Python, PHP, Ruby and Go).
- Direct via Redis Cloud
- Addons using Heroku CLI
- Addons using Heroku Dashboard
Using Redis Cloud directly
Redis is an open source, in-memory, key-value data store most commonly used as a primary database, cache, message broker, and queue. Redis cache delivers sub-millisecond response times, enabling fast and powerful real-time applications in industries such as gaming, fintech, ad-tech, social media, healthcare, and IoT.
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. Redis Cloud allows you to run Redis server over the Cloud and access instance via multiple ways like RedisInsight, redis command line as well as client tools. You can quickly and easily get your apps up and running with Redis Cloud through its Redis Heroku addons , just tell us how much memory you need and get started instantly with your first Redis database. You can then add more Redis databases (each running in a dedicated process, in a non-blocking manner) and increase or decrease the memory size of your plan without affecting your existing data.
::tip INFO Heroku addons are set of tools and services for developing, extending, and operating your app. :::
You can quickly and easily get your apps up and running with Redis Cloud directly. Follow the below steps:
Step 1. Create Redis Cloud
Create your free Redis Cloud account by visiting this link
Follow this link to create a Redis Cloud subscription and database. Once you create the database, you will be provisioned with a unique database endpoint URL, port and password. Save these for future reference.
Before you proceed with heroku redis, ensure that you can connect to Redis instance and verify if it is accessible via redis-cli command. You can run info
command that is available in redis client software to see the version, memory usage, stats, and modules enabled in the Redis cloud database.
Step 2. Create a Heroku account
If you are using Heroku for the first time, create your new Heroku account through this link.
Step 3. Install Heroku CLI on your system
brew install heroku
Step 4. Login to Heroku
heroku login
heroku: Press any key to open up the browser to login or q to exit:
Opening browser to https://cli-auth.heroku.com/auth/cli/browser/XXXXXXXXXXA
Logging in... done
Logged in as your_email_address
Step 5. Connect your application to Redis Cloud
For this demonstration, we will be using a Sample Rate Limiting application.
Clone the repository
git clone https://github.com/redis-developer/basic-rate-limiting-demo-python
Run the commands below to get a functioning Git repository that contains a simple application as well as a package.json file.
heroku create
Creating app... done, ⬢ lit-bayou-75670
https://lit-bayou-75670.herokuapp.com/ | https://git.heroku.com/lit-bayou-75670.git
Step 6. Setting up environment variables
Follow this link to create a Redis Cloud subscription and database connection as shown below: Go to the Heroku dashboard, click "Settings" and set REDIS_URL
and REDIS_PASSWORD
under the Config Vars.
The Redis URL endpoint is unique and might be different in your case. Please enter the values accordingly
Refer to Step 1 for the correct values to use.
Step 7. Pushing the code to Git
git push heroku
remote: -----> Build succeeded!
remote: -----> Discovering process types
remote: Procfile declares types -> web
remote:
remote: -----> Compressing...
remote: Done: 32.9M
remote: -----> Launching...
remote: Released v5
remote: https://lit-bayou-75670.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
To https://git.heroku.com/lit-bayou-75670.git
* [new branch] main -> main
Check the logs:
heroku logs --tail
2021-03-27T03:48:30.000000+00:00 app[api]: Build succeeded
2021-03-27T03:48:33.956884+00:00 heroku[web.1]: Starting process with command `node server/index.js`
2021-03-27T03:48:36.196827+00:00 app[web.1]: App listening on port 11893
Step 8. Accessing the app
Using Heroku CLI
Please note that this method won't allow you to choose Redis Modules while creating your Redis database. Also, it doesn't provide you with the flexibility to choose the Cloud platform of your choice. It is recommended to use Redis Cloud directly. Click here to learn more.
In this section, we will create a Heroku account, use the Heroku CLI to login and add Redis Cloud as an add-on.
Step 1: Install Heroku
$ brew tap heroku/brew && brew install heroku
Assuming that you have already created a Heroku, run the command to below login into Heroku:
$ heroku login
heroku: Press any key to open up the browser to login or q to exit:
Opening browser to https://cli-auth.heroku.com/auth/cli/browser/4788f936-3557-439f-ab37-95338b735cf2?requestor=XXXXXXXXXXXA.vhF7XtVTtsp9xliwwrHG5ytuirrmn9EfT6Ef3WuzXFE
Logging in... done
Logged in as your_email_address
Step 2: Cloning the application
$ git clone https://github.com/redis-developer/basic-redis-rate-limiting-demo-nodejs
Step 3. Create a heroku app
$ heroku create
Creating app... done, ⬢ lit-island-48230
https://lit-island-48230.herokuapp.com/ | https://git.heroku.com/lit-island-48230.git
Step 4. Start by installing the add-on:
Ensure that you don’t have existing add-ons added in your account.
$ heroku addons:create rediscloud -a lit-island-48230
Creating rediscloud on ⬢ lit-island-48230... free
Created rediscloud-asymmetrical-85190 as REDISCLOUD_URL
Use heroku addons:docs rediscloud to view documentation
Once Redis Cloud has been added, you will notice a REDISCLOUD_URL config var in your Heroku config containing the username, password, hostname and port of your first Redis Cloud database.
heroku config:get REDISCLOUD_URL -a lit-island-48230
redis://default:ajSE7DuqhmGG7u2ZbSU0HTuEqTx1FuEQ@redis-17268.c256.us-east-1-2.ec2.cloud.redislabs.com:17268
$ heroku addons:info rediscloud
=== rediscloud-asymmetrical-85190
Attachments: lit-island-48230::REDISCLOUD
Installed at: Fri Mar 26 2021 07:52:43 GMT+0530 (India Standard Time)
Owning app: lit-island-48230
Plan: rediscloud:30
Price: free
State: created
heroku config -a lit-island-48230
=== lit-island-48230 Config Vars
REDISCLOUD_URL: redis://default:ajSE7DuqhmGG7u2ZbSU0HTuEqTx1FuEQ@redis-17268.c256.us-east-1-2.ec2.cloud.redislabs.com:17268
Step 5. Accessing the Redis Cloud dashboard
Go to Heroku and click on “Installed add-ons”:
Click on “Redis Cloud” and you will be redirected to the Redis Cloud Dashboard.
Step 6. Pushing the code to Heroku
$ git push heroku
remote: -----> Launching...
remote: Released v8
remote: https://lit-island-48230.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
To https://git.heroku.com/lit-island-48230.git
* [new branch] master -> master
Step 7. Accessing the app
Open https://lit-island-48230.herokuapp.com/ and access the rate limiting app.
Using Heroku Dashboard
Please note that this method won't allow you to choose Redis Modules while creating a Redis database. Also, it doesn't provide you with the flexibility to choose the Cloud platform of your choice. It is recommended to use Redis Cloud directly. Click here to learn more.
Step 1: Sign up for a Heroku account
Create a Heroku account and sign-in to the dashboard.
Step 2. Create a new Heroku app
Create a new app called "redislabs":
Step 3. Choose GitHub
Select "GitHub" as a deployment method:
Step 4. Connect to GitHub
Step 5. Install Redis Enteprise Cloud as an add-on
Step 6. Fill up order online form
Step 7. Deploy the app
Before deploying the app, modify the environment variables as per your application:
Go to the "Deploy" section of the application dashboard and click on "Deploy Branch":
Click "Open App" on the top right corner.