26
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.
I like to use Vultr (referral link), and I decided to go with Ubuntu 18.04.
Then run
apt update; apt upgrade
Run
sudo apt install redis-server
Run
sudo vim /etc/redis/redis.conf
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.
systemctl restart redis.service
And that should do it. I think. If you have problems, leave a comment and I will get back to you!
26