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 OpenSUSE Leap 15.3.
Related Content
- How to install and configure Redis 6 on FreeBSD 13
- How to install & configure Redis 6 on Rocky Linux/Centos 8
- How to install and configure Redis 6 on Fedora 34
- How to run Redis 6 with Docker and Docker-Compose
- How to Install and Configure Postgres 14 on Fedora 34
- Things to do on a Fresh Fedora 34 Desktop Install
Prerequisites
To follow along, ensure that you have:
- An updated OpenSUSE Leap server
- Access to the Internet
- Root access to the server or user with sudo access
Table of Content
- Update the OpenSUSE Leap server
- Installing Redis
- Configuring Redis
- Connecting and performing basic operations in Redis
- Performing Redis Benchmark
1. Update the OpenSUSE Leap Server
Before proceeding, ensure that the server is updated. We will refresh the repositories then update using this commands:
sudo zypper ref
sudo zypper up -y
Let us also ensure vim is installed using this command since we will use it later:
sudo <meta charset="utf-8">zypper in -y vim
2. Installing redis
Redis 6 is available in the default OpenSUSE Leap Servers. But it is not the latest version. To get the latest version, add the Databases repo using this command:
sudo curl -L -o /etc/zypp/repos.d/server-database.repo https://download.opensuse.org/repositories/server:/database/openSUSE_Leap_15.3/server:database.repo
Confirm the content of the repo using the cat command:
~> cat /etc/zypp/repos.d/server-database.repo
[server_database]
name=Databases (openSUSE_Leap_15.3)
type=rpm-md
baseurl=https://download.opensuse.org/repositories/server:/database/openSUSE_Leap_15.3/
gpgcheck=1
gpgkey=https://download.opensuse.org/repositories/server:/database/openSUSE_Leap_15.3/repodata/repomd.xml.key
enabled=1
Then refresh the repos using this commannd:
sudo zypper ref
Now install redis:
~> sudo zypper in redis
Loading repository data...
Reading installed packages...
Resolving package dependencies...
The following NEW package is going to be installed:
redis
1 new package to install.
Overall download size: 1.1 MiB. Already cached: 0 B. After the operation, additional 4.3 MiB will be used.
Continue? [y/n/v/...? shows all options] (y): y
Retrieving package redis-6.2.6-lp153.178.3.x86_64 (1/1), 1.1 MiB ( 4.3 MiB unpacked)
Retrieving: redis-6.2.6-lp153.178.3.x86_64.rpm ......................................................................................................[done]
Checking for file conflicts: ........................................................................................................................[done]
(1/1) Installing: redis-6.2.6-lp153.178.3.x86_64 ....................................................................................................[done]
Additional rpm output:
useradd -r -s /sbin/nologin -c "User for redis key-value store" -g redis -d /var/lib/redis redis
See /usr/share/doc/packages/redis/README.SUSE to continue
Use this command to confirm the redis package installed:
~> zypper info redis
Loading repository data...
Reading installed packages...
Information for package redis:
------------------------------
Repository : Databases (openSUSE_Leap_15.3)
Name : redis
Version : 6.2.6-lp153.178.3
Arch : x86_64
Vendor : obs://build.opensuse.org/server:database
Installed Size : 4.3 MiB
Installed : Yes
Status : up-to-date
Source package : redis-6.2.6-lp153.178.3.src
Summary : Persistent key-value database
Description :
redis is an advanced key-value store. It is similar to memcached but the dataset
is not volatile, and values can be strings, exactly like in memcached,
but also lists, sets, and ordered sets. All this data types can be manipulated
with atomic operations to push/pop elements, add/remove elements, perform server
side union, intersection, difference between sets, and so forth. Redis supports
different kind of sorting abilities.
Upon installation, I noticed that no systemd service was not added for managing the redis. Let us create a systemd file in this path /etc/systemd/system/redis.service
using this command:
sudo vim /etc/systemd/system/redis.service
The add this content to the file:
[Unit]
Description=Redis In-Memory Data Store
After=network.target
[Service]
User=redis
Group=redis
ExecStart=/usr/sbin/redis-server /etc/redis/redis.conf
LimitNOFILE=10240
ExecStop=/usr/bin/redis-cli shutdown
Restart=always
[Install]
WantedBy=multi-user.target
Create the specified config file
/etc/redis/redis.conf by copying the sample file:sudo cp /etc/redis/default.conf.example /etc/redis/redis.conf
Finally, update the file permission:
sudo chown redis.redis /etc/redis/redis.conf
Now that the service file has been created, let’s start it with this command:
sudo systemctl start redis
Enable the service so it starts on boot:
$ 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 In-Memory Data Store
Loaded: loaded (/etc/systemd/system/redis.service; disabled; vendor preset: disabled)
Active: active (running) since Mon 2021-11-01 07:28:53 UTC; 2min 21s ago
Main PID: 4377 (redis-server)
Tasks: 5 (limit: 4587)
CGroup: /system.slice/redis.service
└─4377 /usr/sbin/redis-server 127.0.0.1:6379
Nov 01 07:28:53 ip-10-2-40-60 systemd[1]: Started Redis In-Memory Data Store.
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 * -::*
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:fa8def48b70298fc redis_mode:standalone os:Linux 5.3.18-59.27-default x86_64 arch_bits:64 multiplexing_api:epoll atomicvar_api:c11-builtin gcc_version:7.5.0 process_id:4590 process_supervised:no run_id:9448d092343987bc83f0c24ff3aa0ce051827e5b tcp_port:6379 server_time_usec:1635752416634177 uptime_in_seconds:334 uptime_in_days:0 hz:10 configured_hz:10 lru_clock:8362464 executable:/usr/sbin/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.18 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.039 milliseconds (cumulative count 1)
50.000% <= 0.111 milliseconds (cumulative count 6640)
75.000% <= 0.119 milliseconds (cumulative count 7573)
87.500% <= 0.183 milliseconds (cumulative count 8767)
93.750% <= 0.255 milliseconds (cumulative count 9439)
96.875% <= 0.383 milliseconds (cumulative count 9705)
98.438% <= 0.607 milliseconds (cumulative count 9847)
99.219% <= 0.887 milliseconds (cumulative count 9923)
99.609% <= 1.047 milliseconds (cumulative count 9963)
99.805% <= 1.231 milliseconds (cumulative count 9981)
99.902% <= 1.991 milliseconds (cumulative count 9991)
99.951% <= 3.095 milliseconds (cumulative count 9999)
99.994% <= 3.103 milliseconds (cumulative count 10000)
100.000% <= 3.103 milliseconds (cumulative count 10000)
Cumulative distribution of latencies:
40.480% <= 0.103 milliseconds (cumulative count 4048)
91.360% <= 0.207 milliseconds (cumulative count 9136)
95.620% <= 0.303 milliseconds (cumulative count 9562)
97.280% <= 0.407 milliseconds (cumulative count 9728)
..........
99.970% <= 0.503 milliseconds (cumulative count 9997)
100.000% <= 0.607 milliseconds (cumulative count 10000)
Summary:
throughput summary: 75187.97 requests per second
latency summary (msec):
avg min p50 p95 p99 max
0.173 0.064 0.167 0.239 0.295 0.583
For more options and examples, use:
$ redis-benchmark --help
Conclusion
We have managed to install and configure Redis 6 in OpenSUSE Leap.