Getting Started with Redis: Installation and Setup Guide


Image by Author

 

Redis is an open-source in-memory data structure storage known for its excellent speed and scalability. This guide provides a comprehensive overview of installing and setting up Redis on various operating systems, including Linux, Windows, and macOS.

You’ll learn how to add a Redis repository, install software, Manage Redis servers, and connect to them using the Redis CLI, whether you’re developing storage-hungry applications. Real-time analysis or data storage This guide will help you with the knowledge to get started with Redis.

Redis was originally developed as a key-value store, but it has evolved into a versatile tool capable of handling many data types and use cases. It is particularly popular for its high performance, as it stores data in memory rather than on disk, allowing for extremely fast read and write operations. This makes Redis an excellent choice for applications that require quick access to frequently changing data, such as real-time analytics, caching, and session management.

Redis’s flexibility allows developers to implement various data structures efficiently, making it suitable for applications in numerous domains, including web development, gaming, IoT, and big data. Its open-source nature means it is freely available and has a large community contributing to its development, ensuring continuous improvements and a wealth of resources.

 

Prerequisites

 
Before you begin the installation and setup process, ensure that you meet the following prerequisites:

  • Basic Knowledge of Command Line: Familiarity with command line operations will help you navigate the installation process smoothly
  • Access to a Computer: You should have a computer running one of the following operating systems:
  • Internet Connection: A stable internet connection is necessary to download Redis and any additional tools
  • Administrator Privileges: Ensure you have the necessary permissions to install software on your computer, especially for Windows and Linux users

 

Step-by-Step Guide for Installation

 

How to Install Redis on Linux

Most major Linux distributions provide packages for Redis, making installation straightforward. Below are detailed steps for installing Redis on Ubuntu/Debian and Red Hat/Rocky Linux.

 

Install on Ubuntu/Debian

  1. Install Required Packages: Before installing Redis, you may need to install some prerequisite packages. Open your terminal and run the following command:
  2.  

    sudo apt-get install lsb-release curl gpg

     

  3. Add the Redis Repository: You must add the official Redis repository to your system’s package manager. Execute the following commands:
  4. curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg
    
    sudo chmod 644 /usr/share/keyrings/redis-archive-keyring.gpg
    
    echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/redis.list

     

  5. Update Package List and Install Redis: Now, update your package list and install Redis:
  6. sudo apt-get update
    sudo apt-get install redis

     

  7. Start Redis Service: Redis should start automatically after installation. If it doesn’t, you can start it manually:
  8. sudo systemctl start redis-server

     

  9. Enable Redis to Start on Boot: To ensure that Redis starts automatically on system boot, run:
  10. sudo systemctl enable redis-server

     

 

Install on Red Hat/Rocky

  1. Install Redis: For Red Hat or Rocky Linux, simply run:
  2.  

  3. Start and Enable Redis: Start Redis and enable it to restart at boot:
  4. sudo systemctl enable redis
    sudo systemctl start redis

     

 

Install on Ubuntu using Snap (OPTIONAL)

To install Redis using Snap, follow these steps:

  1. Update Snap: Open your terminal and run:
  2.  

  3. Install Redis Tools and Redis:
  4. sudo apt install redis-tools # for redis-cli
    sudo snap install redis

     

  5. Manage Redis with Snap: Redis will start automatically but won’t restart at boot time. Use these commands to manage Redis:
  6. sudo snap start redis
    sudo snap stop redis
    sudo snap restart redis
    sudo snap services redis

     

  7. Enable Redis to Start on Boot: To enable Redis to restart at boot, run:
  8. sudo systemctl enable redis

     

 

Starting and Stopping Redis in the Background

To manage the Redis server as a background process, use the systemctl command:

  1. Start Redis:
  2. sudo systemctl start redis-server  # Use redis or redis-server depending on the platform

     

  3. Stop Redis:
  4. sudo systemctl stop redis-server  # Use redis or redis-server depending on the platform

     

 

Test Redis Installation

Once Redis is running, you can test the connection using the Redis CLI:

  1. Launch Redis CLI: Open your terminal and enter:
  2.  

  3. Test the Connection: In the Redis CLI, test the connection by typing:
  4.  
    If Redis is functioning correctly, you should receive a response:

     

If the message appears, the installation is successful.

 

Installing Redis on Windows

 
While Redis is not officially supported on Windows, you can install it for development purposes using Windows Subsystem for Linux (WSL). Follow these steps:
 

Enable WSL2

  1. Check Windows Version: Ensure you are running Windows 10 version 2004 or higher or Windows 11
  2. Install or Enable WSL: Follow Microsoft’s detailed instructions for installing WSL. This guide assumes Ubuntu is the default Linux distribution

 

Install Redis

Once WSL is running with Ubuntu, follow the steps for Ubuntu/Debian to install Redis:

  1. Add the Redis Repository:
  2. curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg
    echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/redis.list

     

  3. Update and Install Redis:
  4. sudo apt-get update
    sudo apt-get install redis

     

  5. Start the Redis Server:
  6. sudo service redis-server start

     

 

Test Redis Installation

Just as with Linux, use the Redis CLI to test your installation:

  1. Launch Redis CLI:
  2.  

  3. Test the Connection:
  4.  

  5. You should see:
  6.  

If the message appears, the installation is successful.

 

Installing Redis on macOS

 
If you’re using macOS, the easiest way to install Redis is through Homebrew. Here’s how:

 

Prerequisites

First, make sure you have Homebrew installed. Install Homebrew on macOS (If you haven’t Installed it already)

Open your terminal and run:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

 

Follow the on-screen instructions to complete the installation. To check if Homebrew was installed successfully, run:

 

Install Redis

Once Homebrew is installed, you can install Redis with the following command:

 

Start Redis

  1. After installation, you can start Redis using:
  2. brew services start redis

     

  3. This command sets Redis to start automatically at login. If you prefer to start it manually, use:

     

 

Test Redis

  1. You can test if Redis is running by opening another Terminal window and typing:
  2.  

  3. This opens the Redis command-line interface. You can then test the connection by typing:
  4.  

  5. You should see:
  6.  

If the message appears, the installation is successful.

 

Conclusion

 
In this tutorial, we covered the installation and setup of Redis on various operating systems, including Windows, macOS, and Linux. We also explored how to connect to Redis and test its functionality. Redis’s versatility and performance make it a valuable tool for developers looking to manage data efficiently in their applications.

As you continue your journey with Redis, consider exploring its extensive documentation and community resources to unlock its full potential.
 
 

Shittu Olumide is a software engineer and technical writer passionate about leveraging cutting-edge technologies to craft compelling narratives, with a keen eye for detail and a knack for simplifying complex concepts. You can also find Shittu on Twitter.



Recent Articles

Related Stories

Leave A Reply

Please enter your comment!
Please enter your name here