DEV Community

Christopher Kapic
Christopher Kapic

Posted on • Originally published at blog.kapic.io on

How to deploy a Redis instance

For part of my development of TickerTab, I need to create an instance of Redis, an in-memory key:value database for caching. Initially, when I created TickerTab, I had a NodeJS API, but I am refactoring to use Netlify's serverless functions. Since my functions are serverless, I cannot cache on the same server that the functions are run on (like I could with NodeJS), so I need a separate server.

This is how to set up an independent instance of Redis.

Note: I don't know what I'm doing when it comes to security—if you know something I don't, send me an email. Thanks!

Another note: I now have better ideas about how to handle caching for Netlify. Keep an eye out for another article about a better method.

1. Create a VPS

I like to use Vultr (referral link), and I decided to go with Ubuntu 18.04.

2. SSH into the VPS

Then run

apt update; apt upgrade
Enter fullscreen mode Exit fullscreen mode

3. Install Redis

Run

sudo apt install redis-server
Enter fullscreen mode Exit fullscreen mode

4. Update the configuration

Run

sudo vim /etc/redis/redis.conf
Enter fullscreen mode Exit fullscreen mode

And change the following:

# /etc/redis/redis.conf
# 
# previously:
# supervised no
# now:
supervised systemd

# previously:
bind 127.0.0.1 ::1
# now:
# bind 127.0.0.1 ::1
# NOTE: Generally, this is a big security risk,
# but since we are using serverless functions we
# don't know which IP address we will receive a
# connection from.

# previously:
# requirepass foobared
# now:
requirepass YOURSUPERSTRONGPASSWORD
# NOTE: Use a long password. If you don't, Redis
# is fast enough that a brute force attack would
# not be very difficult.
Enter fullscreen mode Exit fullscreen mode

5. Run Redis

systemctl restart redis.service
Enter fullscreen mode Exit fullscreen mode

And that should do it. I think. If you have problems, leave a comment and I will get back to you!

Top comments (0)