How to install and set up Redis
3 simple ways
Redis is an in-memory data structure store, used as a database, cache, and message broker that allows for incredibly fast read and write ops.
We are going to see 3 ways of setting up Redis. I will be using Ubuntu 20.04 for this tutorial.
1. Installing Redis Locally
To install Redis on your system execute the following command.
sudo apt update sudo apt install redis-server
You need to configure a couple of thing after this, use any editor and change the
supervised directive to
sudo nano /etc/redis/redis.conf
You can also set your redis password, since Redis is pretty fast you will need a very strong password. Use the following command to generate one.
openssl rand 60 | openssl base64 -A
Save the files and restart the Redis service to check if its running.
sudo systemctl restart redis.service sudo systemctl status redis
2. Use a Docker Image
This is probably the simplest of all the ways. Pull the Redis docker image
docker pull redis
And spin up a redis container
docker run --name some-redis -d redis
Once you are done you can configure the Redis image just like we configured it locally, just enter bash inside your container using the following command and then set the password.
docker exec -it some-redis bash
3. Managed Redis Labs instance
You can also use a free tier instance from Redis Labs.
Create an account and select your favourite cloud provider.
I'm gonna select the 30 MB free tier, that's more than enough for our project.
You will be directed to set up a database: A few things to consider here:
- Type of eviction policy (I highly recommend setting up an eviction policy).
- If you want to use a Redis module, you can set it up here.
I have selected the allkeys-lru eviction policy and no modules.
This blog is part of a series, in the next part, we will set up our node server to cache data with Redis. You can continue with the series using any of the Redis setups mentioned in this blog.
Refs & Resources
If you loved the article and would like to support me