Contents

    Guides

    Setting up Redis on a Remote Server

    Somtochukwu Uchegbu

    Somtochukwu is a Technical Writer who enjoys writing technical articles that explain technical concepts.

    Published on

    August 23, 2022
    Setting up Redis on a Remote Server

    Software engineers have always been tasked with integrating third-party applications for multiple components of a product. This may have underlying consequences later on when engineers have many third-party applications to work with within the product. In turn, it may cause inefficient management of components within the application, which will cause different issues.

    Over time, developers have sought to build more robust third-party applications that can handle more than one task at a time. Today we will be looking at one of those applications called Redis.

    In this article,  we are going to know how to set up Redis on a remote server, but first, how about we go through the basics of Redis; what Redis is, the different use cases of Redis, and most importantly, why we should use Redis. Without further delay, let's get right into it.

    What is Redis?

    According to the official Redis documentation:

    Redis is an open-source (BSD licensed), in-memory data structure store used as a database, cache, message broker, and streaming engine.

    In short, Redis which stands for Remote Dictionary Server is an open-source software with an in-memory data store that can function as a database, cache, message broker, or streaming engine.

    It also provides data structures for us to work with in development or production such as strings, lists, hashes, sets, sorted lists, etc.
    Redis has a lot packed within it, you need to find out what you particularly need it for.

    Redis as a Database

    As discussed earlier, Redis can be used as a primary or a secondary database, depending on your use case. It is most commonly used as a primary database rather than a secondary database.

    Advantages of Redis as a Database

    There are benefits to using Redis as a primary database, such as:

    • Low latency in data retrieval.
    • Increase speed for read-write operations to the database.
    • Easy scalability of database systems.

    Redis as a Cache

    The most common use of Redis is as a cache, because of the in-memory data store Redis offers, it is most efficient as a cache. It is by far one of the best caching systems we have there.

    Advantages of Redis as a Cache

    There are advantages to using Redis as a Cache as well, some of which are:

    • It increases the speed of read-write operations in the data store.
    • It supports data persistence.
    • It is easy to use.

    Redis as a Message Broker

    Redis can also be used as a message broker, it can be used to allow communication between two services. An example would be using Redis as a message broker within microservices. It is efficient, fast, and reliable.

    Why use Redis?

    There are tons of reasons to use Redis. It depends on what area you want to use Redis for, but as a tool, Redis is amazing. I will highlight some reasons why you should use Redis.

    • Redis is a fast and reliable cache
    • It also couples as a database, message broker, and streaming engine.
    • It offers high availability and is easily scalable.
    • It is a simple-to-use tool that enables us to write fewer lines of code to store and access data
    • It enables us to store different types of data structures within the key: value data store.

    How to set up Redis on a Remote Server

    In this section, we will see how to set up Redis on a remote server so we can access it anywhere on the internet.
    For this setup, we will need to have a Linode account. If you do not have a Linode account, you can head up to cloud.linode.com to signup for a free tier account to follow up with this setup.

    After completing the signup process, you should be greeted with this page.

    Cloud Linode user dashboard view

    Next, we will need to create a virtual machine(VM) on which we will install Redis on. To create a virtual machine, click on the Create Linode button.

    We should see a configuration screen next, on here, we are going to select the configurations of our virtual machine.

    View of Linode's Distribution and Region selection screen

    For our Linux distribution, make sure to choose Ubuntu 22.04, and for the region, choose a region that is closest to you for faster availability.

    View of Linode configuration selection screen

    The next configuration is the Linode Plan. Make sure to choose the Nanode 1GB, this is the smallest Linode plan Linode has to offer, for this tutorial, we are going to stick with the configurations that have the smallest amount.

    View of Linode's label and root password screen

    Next, we can see the Linode Label. Linode assigns a default label to every VM if a custom label is not provided. We can change the Linode Label if we want to.

    We can see the Root Password, this is the root password we will use to log in to our VM.

    Make sure to select the smallest, or the least resources for the virtual machine so as not to burn through the free tier package.

    View of Linode's add-on screen

    We do not need to worry about the additional settings below. To create our VM click the Create Linode button.

    After setting up our VM, we need to login into the VM so we can install Redis. On the right side of the management console, we should see an SSH login command.

    We need to copy the command and run it on our terminal like so:

    ssh root@

    Now, we should be logged in to our VM, we need to run these commands to upgrade and update our VM:

    apt-get upgrade 
    apt-get update

    Next, we need to install Redis, like so:

    apt-get install redis

    After Redis is done installing, to check if Redis is up and running, we need to type in this command into our terminal:

    systemctl redis status

    We should see this output

    ● redis-server.service - Advanced key-value store 
        Loaded: loaded (/lib/systemd/system/redis-server.service; enabled; vendor > 
        Active: active (running) since Wed 2022-07-13 12:59:12 UTC; 54s ago 
          Docs: http://redis.io/documentation, man:redis-server(1) 
      Main PID: 13256 (redis-server) 
         Status: "Ready to accept connections" 
          Tasks: 5 (limit: 4579) 
         Memory: 2.6M 
            CPU: 86ms 
         CGroup: /system.slice/redis-server.service 
                      └─13256 "/usr/bin/redis-server 127.0.0.1:6379" "" "" "" "" "" "" "> 
    
    Jul 13 12:59:12 localhost systemd[1]: Starting Advanced key-value store... 
    Jul 13 12:59:12 localhost systemd[1]: Started Advanced key-value store. 
    lines 1-15/15 (END)

    We have confirmed that Redis is running successfully on our server. But we have not set it up for us to access it anywhere. Now we need to make a few changes to the Redis configuration file to make sure we can access our Redis server anywhere.

    If we type in the redis-cli command, we will see this output:

    127.0.0.1:6379>

    This shows that Redis is still running on our VM’s localhost.

    We need to edit the config file at /etc/redis/redis.conf.

    Firstly, we need to open the file, we can do this with nano like so:

    nano /etc/redis/redis.conf

    Next, we need to scroll down to line 66 where we have bind 127.0.0.1 ::1, like so:

    View of root localhost line 66

    We need to replace 127.0.0.1 ::1 with our IP address. For me it will be:

    bind 139.144.51.58

    After the edit, we need to run this command in our VM so that Redis picks up the changes

    systemctl restart redis

    Now, when we run this command, we can access the Redis server on our VM anywhere

    redis-cli -h ip address

    After running this command we should get an output with this form

    ip address:6379>

    Now we can use the Redis Server we set up on our VM.

    Conclusion

    To summarize, we went through some important areas of Redis, for example, what Redis is, the major applications of Redis, why we should use Redis, and most importantly, how to set up Redis on a remote server. We hope you found this article informative and interesting.

    Data-rich bug reports loved by everyone

    Get visual proof, steps to reproduce and technical logs with one click

    Make bug reporting 50% faster and 100% less painful

    Rating LogosStars
    4.6
    |
    Category leader

    Liked the article? Spread the word

    Put your knowledge to practice

    Try Bird on your next bug - you’ll love it

    “Game changer”

    Julie, Head of QA

    star-ratingstar-ratingstar-ratingstar-ratingstar-rating

    Overall rating: 4.7/5

    Try Bird later, from your desktop