How to install and set up Redis

3 simple ways

·

2 min read

How to install and set up Redis

Redis

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 systemd.

sudo nano /etc/redis/redis.conf

changing the supervised directive to systemd

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

Set password as the string generated by the above command

Save the files and restart the Redis service to check if its running.

sudo systemctl restart redis.service
sudo systemctl status redis

Restart Redis service to check status

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. Redis Labs set up initial screen

I'm gonna select the 30 MB free tier, that's more than enough for our project.

Redis Labs select subscription

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.

Setting up a database on 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.

Feel free to reach out to me on Twitter @cryptus_neoxys and connect with me on LinkedIn.


Refs & Resources

https://www.digitalocean.com/community/tutorials/how-to-install-and-secure-redis-on-ubuntu-18-04

https://redis.io/download

GitHub/awesome-redis

If you loved the article and would like to support me