Redis is a free and open-source in-memory data store used all over the world. It mainly serves as a distributed in-memory key-value database, cache, or message broker. Redis supports several data structures such as Lists, Hashes, Sets, Strings e.t.c

Redis can be installed as a standalone server or as a high availability cluster in a production environment using Redis Sentinel. More information on how to set up a Redis cluster has been captured in the guide below:

Redis is known for holding a high reputation for high performance, broad support, high availability, and flexibility. There are several other features associated with Redis such as:

  • In-memory data structures: Redis is a well-known data structure server that offers support for lists, strings, hashes, sorted sets, sets, streams e.t.c
  • Extensibility: It provides a module API that can be used to build extensions in C, C++, and Rust languages.
  • Persistence: It keeps that dataset in memory to allow fast access. Redis can also be configured to persist the data by writing it to a permanent storage disk to survive reboots.
  • Clustering: It supports horizontal scalability with hash-based sharding and can scale to millions of nodes with automatic re-partitioning when the cluster is growing.
  • High availability: It offers replication with automatic failover in both standalone and clustered modes.
  • Programmability: It allows server-side scripting with Lua and server-side stored procedures with Redis Functions.

Due to the amazing features, Redis finds use in the following areas:

  • Streaming and messaging: where high-speed data ingestion, messaging, event sourcing, and notifications are required.
  • Caching and session storage: its speed makes it perfect for caching database queries, API calls, complex computations, and session state
  • Real-time data store: Redis provides in-memory data structures that can allow you to build real-time applications with low latency and high performance.

By following this guide to the end, you should be able to install and configure Redis Server on Rocky Linux 9.

1. Install Redis on Rocky Linux 9

Redis 6.2 resides in the default Rocky Linux 9 repositories and can be installed by running the command:

sudo dnf install vim redis

Dependency Tree:

Transaction Summary
================================================================================
Install  1 Package

Total download size: 1.3 M
Installed size: 4.7 M
Is this ok [y/N]: y

Wait for the installation to complete then start and enable the service:

sudo systemctl start redis
sudo systemctl enable redis

Verify if the service is running:

$ systemctl status redis
● redis.service - Redis persistent key-value database
     Loaded: loaded (/usr/lib/systemd/system/redis.service; enabled; vendor preset: disabled)
    Drop-In: /etc/systemd/system/redis.service.d
             └─limit.conf
     Active: active (running) since Fri 2022-07-29 14:07:36 CEST; 7s ago
   Main PID: 31290 (redis-server)
     Status: "Ready to accept connections"
      Tasks: 5 (limit: 23441)
     Memory: 7.3M
        CPU: 15ms
     CGroup: /system.slice/redis.service
             └─31290 "/usr/bin/redis-server 127.0.0.1:6379"

Check the installed version:

$ redis-server --version
Redis server v=6.2.6 sha=00000000:0 malloc=jemalloc-5.1.0 bits=64 build=9664d239a7dd0d5e

$ redis-cli --version
redis-cli 6.2.6

2. Configure Redis on Rocky Linux 9

Redis stores its configuration file at /etc/redis/redis.conf. This file can be edited as desired.

First, open the file for editing;

sudo vim /etc/redis/redis.conf

In the file, there are several adjustments you can make. These are:

Bind Address

by default, Redis is configured to listen on localhost. This can be changed to you IP address as shown:

bind 127.0.0.1 -::1 192.168.205.12

Daemonize Redis

This allows Redis to run as a daemon

daemonize yes

Set the service to interact with systemd.

supervised systemd

Secure Redis

The Redis server is not secure by default, anyone can access it and manipulate the data. To secure it, set a password as shown;

requirepass  StrongPassword

Once the desired configurations have been made, save the file and restart the service:

sudo systemctl daemon-reload
sudo systemctl restart redis

Redis listens on port 6379 by default, allow this port through the firewall;

sudo firewall-cmd --zone=public --permanent --add-port=6379/tcp
sudo firewall-cmd --reload

3. Using Redis on Rocky Linux 9

Redis can be accessed and used using the Redis CLI from the localhost as shown;

$ redis-cli

Then authenticate to the database using the command:

127.0.0.1:6379> auth StrongPassword
OK
127.0.0.1:6379> exit

Alternatively, you can authenticate to the database with a single command. For example;

$ redis-cli -a StrongPassword