How to Install Redis on Rocky Linux 9

Introduction

Redis is an in-memory data store used as a database, cache, and message broker. It supports various data structures like strings, hashes, lists, and sets. Known for high performance and scalability, Redis handles real-time tasks efficiently, making it ideal for applications like session management, caching, and real-time analytics.

This guide shows you how to install and configure Redis on Rocky Linux 9.

Prerequisites

Before you begin, ensure you have the following:

Update System Packages

Update your system packages to get the latest versions from the repositories. This step ensures applications' security, performance, and compatibility.

  1. Update your system's package information index index.

    CONSOLE
    $ sudo dnf update -y
    
  2. Install the epel-release package for additional software repositories.

    CONSOLE
    $ sudo dnf install epel-release -y
    
  3. Install Redis package.

    CONSOLE
    $ sudo dnf install redis -y
    
  4. Check the Redis version.

    CONSOLE
    $ redis-cli --version   
    

Manage Redis Service

This section explains how to manage the Redis service using systemctl.

  1. Start the Redis service.

    CONSOLE
    $ sudo systemctl start redis
    
  2. Enable the Redis service to start at boot.

    CONSOLE
    $ sudo systemctl enable redis
    
  3. Stop the Redis service.

    CONSOLE
    $ sudo systemctl restart redis
    
  4. Start the Redis service.

    CONSOLE
    $ sudo systemctl start redis
    
  5. Check the status of the Redis service.

    CONSOLE
    $ sudo systemctl status redis
    

Secure Redis Server with a Password

For added security, configure Redis to require a password.

  1. Open the Redis configuration file.

    CONSOLE
    $ sudo nano /etc/redis.conf
    
  2. Find the line that begins with # requirepass.

    INI
    # requirepass
    
  3. Uncomment it by removing the # symbol and set a strong password.

    INI
    requirepass your_secure_password
    
  4. Save the file and exit the text editor.

  5. Restart Redis to apply the changes.

    CONSOLE
    $ sudo systemctl restart redis
    

Understand Redis Directory Structure

This section explains the Redis directory structure, configuration files, error files, and log files.

  • Redis main configuration file.

    /etc/redis.conf
    
  • Redis data directory.

    /var/lib/redis
    
  • Redis Log files.

    /var/log/redis
    
  • Redis error logs.

    /var/log/redis/redis.log
    

Test the Redis Server

This section shows you how to log in to the Redis server, set a key, and retrieve the key.

  1. Connect to the Redis server using the Redis CLI.

    CONSOLE
    $ redis-cli
    
  2. Authenticate to the Redis server and enter the password you set earlier.

    CONSOLE
    auth your_secure_password
    
  3. Set a sample test key and set hello as the value.

    CONSOLE
    set example hello
    
  4. Retrieve the value of the test key.

    CONSOLE
    get test
    

Conclusion

You have successfully installed and configured Redis on Rocky Linux 9. You learned how to update system packages, install Redis, manage the Redis service using systemctl, secure the Redis server with a password, understand the Redis directory structure, and log in to the Redis server to set and retrieve keys. With Redis up and running, you can now explore its various features and capabilities to enhance your applications.

  • Databases
  • Webservers
  • PHP
  • API
  • Python
  • VPS Guides
  • Network
  • AI
  • Node.js