DEV Community

Cover image for Host and Use Redis for Free
Ramki Pitchala
Ramki Pitchala

Posted on • Edited on

Host and Use Redis for Free

This article was originally posted on Medium. If you prefer reading it from there, please do check it out.

Introduction

Although building software projects can be challenging, deployment can be a pain.

In fact, in situations where speed is necessary, deployment must be seamless. For that reason, I want to show you how to deploy Redis for free and use Redis remotely.

Redis Labs, a Redis cloud hosting service, offers a free plan with simple deployment steps. We will leverage that plan to create an instance and integrate that instance with Node.js.

Walk Through

Do everything quickly and well.
― G.I. Gurdjieff

To start, head over to https://redislabs.com/ and sign up.

Photo by Author

Once you create and verify your account, you will end up on this screen.

Photo by Author

Click “Create your subscription”.

Scroll down to “Fixed size” and pick the free option.

Photo by Author

Click “Create”. We now need to create our database under the subscription.

Photo by Author

Enter in the database name. Be sure to copy “Redis Password”. Once you are ready, click “Activate”.

Photo by Author

We can use the endpoint to connect to our remote instance so be sure to copy it down. For security reasons, be careful with who you expose your endpoint to.

It is really that quick!

Integration

Let’s connect to our remote Redis instance! Although I will use Node.js, the connection process will most likely be similar to the other technologies.

Start by creating a new npm project.

npm init
Enter fullscreen mode Exit fullscreen mode

After filling out the project details, cd into your project and install redis, a Node.js client for Redis, and dotenv, an environment variable loader.

npm install redis

npm install dotenv --save-dev
Enter fullscreen mode Exit fullscreen mode

In the root directory, create a file called .env . In it, let’s put our Redis instance hostname, port, and password.

We can find the hostname, port, and password in the View Database section:

Photo by Author

Contents of .env:



    REDIS_HOSTNAME=YOUR REDIS HOSTNAME
    REDIS_PORT=YOUR REDIS PORT
    REDIS_PASSWORD=YOUR REDIS PASSWORD


Enter fullscreen mode Exit fullscreen mode

Create index.js. Let’s say this is where we want to connect to our remote instance. Let’s create a client and test if we can connect to it.

Now we can connect to our Redis instance from Node.js!

Conclusion

I wanted to show a simple way to deploy and use Redis for free, whether it be for demoing a project at a hackathon or evaluating a proof of concept idea.

Thank you for taking the time to read this blog!

Top comments (11)

Collapse
 
ceddy profile image
Ceddy Muhoza

Checkout Upstash too!

Collapse
 
ramko9999 profile image
Ramki Pitchala

Yeah it looks promising!

Collapse
 
aehelaly profile image
Ahmad Helaly

Thx a lot, Upstash is EXACTLY what I have been searching for :)

Collapse
 
amreshsinha profile image
Amresh Prasad Sinha • Edited

Is it now not working? I tried the exact same thing but it prints out nothing on the console.
Here's the code:

const redis = require("redis");
require("dotenv").config();

const client = redis.createClient({
  host: process.env.REDIS_URI,
  port: process.env.REDIS_PORT,
  password: process.env.REDIS_PASSWORD
});

client.on("connect", () => {
  console.log("Connected to our redis instance!");
  client.set("Greatest Basketball Player", "Lebron James");
});
Enter fullscreen mode Exit fullscreen mode

One more thing... This thing works fine in npm package redis@3.1.2 but not with latest 4.0.3 (as of now)

Any help will be appreciated.
Thanks!

Collapse
 
ramko9999 profile image
Ramki Pitchala

I see, so if I understand it correctly. There wasn't an error with redis@3.1.2 but it didn't print "Connected to our redis instance!" to the console. But with 4.0.3, it gave an error when compiling?

Collapse
 
zilti_500 profile image
Daniel Ziltener

It is like everyone magically forgot how to install software, and now it's "did you already use this cool cloud service that totally doesn't do exactly what you could achieve by zypper in redis?"

Collapse
 
ramko9999 profile image
Ramki Pitchala

I will look into zypper.

Collapse
 
yashspr profile image
Yashas Reddy

Thanks. This is helpful for windows users.

Collapse
 
codingjlu profile image
codingjlu

This (redis-windws) worked perfectly for me on Windows :)

Collapse
 
gealber profile image
Gealber Morales

Thanks for sharing this, it was pretty useful for me.

Collapse
 
gopeeey profile image
gopeeey

Thank you so much for this