How to install and configure Redis 6 on Fedora 34

Redis is an in-memory data structure store, used as a distributed, in-memory key–value database, cache and message broker, with optional durability. Redis supports different kinds of abstract data structures, such as strings, lists, maps, sets, sorted sets, HyperLogLogs, bitmaps, streams, and spatial indices.

In this tutorial we are going to learn how to install Redis 6 on Fedora 34.

Prerequisites

To follow along, ensure that you have:

  • An updated Fedora 34 server
  • Access to the Internet
  • Root access to the server or user with sudo access

Table of Content

  1. Update Fedora 34 Server
  2. Installing Redis
  3. Configuring Redis
  4. Connecting and performing basic operations in Redis
  5. Performing Redis Benchmark

1. Update Fedora 34 Server

Before proceeding, ensure that the server is updated using this command:

sudo dnf -y update

Let us also ensure vim is installed using this command since we will use it later:

sudo dnf install -y vim

2. Installing redis

Redis is available in the default Fedora 34 repositories. To install it, use this command:

sudo dnf install redis

Use this command to confirm the redis package installed:

# rpm -qi redis
Name        : redis
Version     : 6.2.6
Release     : 1.fc34
Architecture: x86_64
Install Date: Thu 28 Oct 2021 07:22:18 PM UTC
Group       : Unspecified
Size        : 4939623
License     : BSD and MIT
Signature   : RSA/SHA256, Mon 04 Oct 2021 02:11:42 PM UTC, Key ID 1161ae6945719a39
Source RPM  : redis-6.2.6-1.fc34.src.rpm
Build Date  : Mon 04 Oct 2021 02:04:48 PM UTC
Build Host  : buildvm-x86-25.iad2.fedoraproject.org
Packager    : Fedora Project
Vendor      : Fedora Project
URL         : https://redis.io
Bug URL     : https://bugz.fedoraproject.org/redis
Summary     : A persistent key-value database
Description :
Redis is an advanced key-value store. It is often referred to as a data
structure server since keys can contain strings, hashes, lists, sets and
sorted sets.

You can run atomic operations on these types, like appending to a string;
incrementing the value in a hash; pushing to a list; computing set
intersection, union and difference; or getting the member with highest
ranking in a sorted set.

In order to achieve its outstanding performance, Redis works with an
in-memory dataset. Depending on your use case, you can persist it either
by dumping the dataset to disk every once in a while, or by appending
each command to a log.

Redis also supports trivial-to-setup master-slave replication, with very
fast non-blocking first synchronization, auto-reconnection on net split
and so forth.

Other features include Transactions, Pub/Sub, Lua scripting, Keys with a
limited time-to-live, and configuration settings to make Redis behave like
a cache.

You can use Redis from most programming languages also.

Now that the service has been installed, let’s start it with this command:

sudo systemctl start redis

Enable the service so it starts on boot:

<meta charset="utf-8">$ sudo systemctl enable redis
Created symlink /etc/systemd/system/multi-user.target.wants/redis.service → /usr/lib/systemd/system/redis.service.

After the service starts, use this command to check the status of the service:

$ sudo systemctl status redis
● redis.service - Redis persistent key-value database
     Loaded: loaded (/usr/lib/systemd/system/redis.service; disabled; vendor preset: disabled)
    Drop-In: /etc/systemd/system/redis.service.d
             └─limit.conf
     Active: active (running) since Thu 2021-10-28 19:34:31 UTC; 9s ago
   Main PID: 27610 (redis-server)
     Status: "Ready to accept connections"
      Tasks: 5 (limit: 4603)
     Memory: 2.1M
        CPU: 22ms
     CGroup: /system.slice/redis.service
             └─27610 /usr/bin/redis-server 127.0.0.1:6379

Oct 28 19:34:31 ip-10-2-40-182.us-west-2.compute.internal systemd[1]: Starting Redis persistent key-value database...
Oct 28 19:34:31 ip-10-2-40-182.us-west-2.compute.internal systemd[1]: Started Redis persistent key-value database.

The

Active: active (running) means that the service has been started successfully.

3. Configuring Redis

The redis configuration file is located in this path

/etc/redis/redis.conf. In this section, we are going to update the redis configuration file to allow remote access, to set an authentication password, to add a pid file and to

Set Persistent Store for Recovery.

Edit redis config file using this:

sudo vim /etc/redis/redis.conf

To allow remote access to the redis instance, bind redis to 0.0.0.0 using this line:

bind 0.0.0.0

To set password in redis, use this:

requirepass j2GfJuLFR8

To add a pid file to redis:

pidfile /var/run/redis/redis-server.pid

Set Persistent Store for Recovery by changing the appendonlyvalue to yes

appendonly yes
appendfilename "appendonly.aof"

Restart redis service to apply changes:

sudo systemctl restart redis

4. Connecting and performing basic operations in Redis

If you have an active firewalld service, allow port 6379

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

Connecting to redis locally:

$ redis-cli

To authenticate:

127.0.0.1:6379> auth j2GfJuLFR8
OK

You should receive OK in the output. If you input a wrong password, Authentication should fail.

Check redis information.

127.0.0.1:6379> INFO

This will output a long list of data. You can limit the output by passing Section as an argument. E.g.

127.0.0.1:6379> INFO Server
# Server
redis_version:6.2.6
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:db74a1b227e296fe
redis_mode:standalone
os:Linux 5.11.12-300.fc34.x86_64 x86_64
arch_bits:64
multiplexing_api:epoll
atomicvar_api:atomic-builtin
gcc_version:11.2.1
process_id:27781
process_supervised:systemd
run_id:9ba7b7785f0905ecc4dc3a6ecda2ffe5beaec53a
tcp_port:6379
server_time_usec:1635451060104781
uptime_in_seconds:241
uptime_in_days:0
hz:10
configured_hz:10
lru_clock:8061108
executable:/usr/bin/redis-server
config_file:/etc/redis/redis.conf
io_threads_active:0

5. Performing Redis Benchmarking

Run the benchmark with 15 parallel connections, for a total of 10k requests, against local redis to test its performance.

$ redis-benchmark -h 127.0.0.1 -p 6379 -n 10000 -c 15 -a j2GfJuLFR8
====== PING_INLINE ======
  10000 requests completed in 0.23 seconds
  15 parallel clients
  3 bytes payload
  keep alive: 1
  host configuration "save": 3600 1 300 100 60 10000
  host configuration "appendonly": no
  multi-thread: no

Latency by percentile distribution:
0.000% <= 0.055 milliseconds (cumulative count 2)
50.000% <= 0.127 milliseconds (cumulative count 5509)
75.000% <= 0.159 milliseconds (cumulative count 7514)

..........

99.940% <= 0.503 milliseconds (cumulative count 9994)
100.000% <= 0.607 milliseconds (cumulative count 10000)

Summary:
  throughput summary: 74074.07 requests per second
  latency summary (msec):
          avg       min       p50       p95       p99       max
        0.159     0.072     0.151     0.239     0.279     0.567

For more options and examples, use:

$ redis-benchmark --help

Conclusion

We have managed to install and configure Redis 6 in Fedora 34.

comments powered by Disqus
Citizix Ltd
Built with Hugo
Theme Stack designed by Jimmy