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 Ubuntu 20.04.
Related Content
Prerequisites
To follow along, ensure that you have:
- An updated Ubuntu server
- Access to the Internet
- Root access to the server or user with sudo access
Update the Ubuntu Server
Before proceeding, ensure that the server is updated using this command (as a root user):
1
2
| sudo apt update
sudo apt -y upgrade
|
Let us also ensure vim is installed using this command since we will use it later:
1
| sudo apt install -y vim
|
Installing redis
You can install recent stable versions of Redis from the official packages.redis.io
APT repository. Add the repository to the apt
index, update it and install:
1
2
3
4
| curl https://packages.redis.io/gpg | sudo apt-key add -
echo "deb https://packages.redis.io/deb $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/redis.list
sudo apt-get update
sudo apt-get install redis
|
Use this command to confirm the redis package installed:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
| $ apt-cache policy info redis
info:
Installed: 6.7.0.dfsg.2-5
Candidate: 6.7.0.dfsg.2-5
Version table:
*** 6.7.0.dfsg.2-5 500
500 http://us-west-2.ec2.archive.ubuntu.com/ubuntu focal/main amd64 Packages
100 /var/lib/dpkg/status
redis:
Installed: 6:6.2.6-3rl1~focal1
Candidate: 6:6.2.6-3rl1~focal1
Version table:
*** 6:6.2.6-3rl1~focal1 500
500 https://packages.redis.io/deb focal/main amd64 Packages
500 https://packages.redis.io/deb focal/main all Packages
100 /var/lib/dpkg/status
6:6.2.6-2rl1~focal1 500
500 https://packages.redis.io/deb focal/main amd64 Packages
500 https://packages.redis.io/deb focal/main all Packages
6:6.2.6-1rl1~focal1 500
500 https://packages.redis.io/deb focal/main amd64 Packages
500 https://packages.redis.io/deb focal/main all Packages
6:6.2.5-1rl1~focal1 500
500 https://packages.redis.io/deb focal/main amd64 Packages
500 https://packages.redis.io/deb focal/main all Packages
6:6.2.4-1rl1~focal1 500
500 https://packages.redis.io/deb focal/main amd64 Packages
500 https://packages.redis.io/deb focal/main all Packages
6:6.0.16-3rl1~focal1 500
500 https://packages.redis.io/deb focal/main amd64 Packages
500 https://packages.redis.io/deb focal/main all Packages
|
Now that the service has been installed, let’s start it with this command:
1
| sudo systemctl start redis-server
|
Enable the service so it starts on boot:
1
| sudo systemctl enable redis-server
|
After the service starts, use this command to check the status of the service:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
| $ sudo systemctl status redis-server
● redis-server.service - Advanced key-value store
Loaded: loaded (/lib/systemd/system/redis-server.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2021-11-19 13:46:56 EAT; 1min 3s ago
Docs: http://redis.io/documentation,
man:redis-server(1)
Main PID: 250930 (redis-server)
Status: "Ready to accept connections"
Tasks: 5 (limit: 4631)
Memory: 2.1M
CGroup: /system.slice/redis-server.service
└─250930 /usr/bin/redis-server 127.0.0.1:6379
Nov 19 13:46:56 ubuntu-client.citizix.com systemd[1]: Starting Advanced key-value store...
Nov 19 13:46:56 ubuntu-client.citizix.com systemd[1]: Started Advanced key-value store.
|
The above indicates 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:
1
| vim /etc/redis/redis.conf
|
To allow remote access to the redis instance, bind redis to 0.0.0.0
using this line:
To set password in redis, use this:
To add a pid file to redis:
1
| pidfile /var/run/redis/redis-server.pid
|
Set Persistent Store for Recovery by changing the appendonlyvalue to yes
1
2
| appendonly yes
appendfilename "appendonly.aof"
|
Restart redis service to apply changes:
1
| sudo systemctl restart redis-server
|
Connecting to redis locally:
To authenticate:
1
2
3
| 127.0.0.1:6379> auth j2GfJuLFR8
OK
127.0.0.1:6379>
|
You should receive OK
in the output. If you input a wrong password, Authentication should fail.
Check redis information.
This will output a long list of data. You can limit the output by passing Section as an argument. E.g.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
| 127.0.0.1:6379> INFO Server
# Server
redis_version:6.2.6
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:557672d61c1e18ba
redis_mode:standalone
os:Linux 5.11.0-1019-aws x86_64
arch_bits:64
multiplexing_api:epoll
atomicvar_api:c11-builtin
gcc_version:9.3.0
process_id:251198
process_supervised:systemd
run_id:9a4f90740c3f6a327b521f928e7e6f9405a1fc51
tcp_port:6379
server_time_usec:1637319052373797
uptime_in_seconds:28
uptime_in_days:0
hz:10
configured_hz:10
lru_clock:9929100
executable:/usr/bin/redis-server
config_file:/etc/redis/redis.conf
io_threads_active:0
|
Run the benchmark with 15
parallel connections, for a total of 10k
requests, against local redis to test its performance.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
| $ 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.031 milliseconds (cumulative count 1)
50.000% <= 0.095 milliseconds (cumulative count 6342)
75.000% <= 0.103 milliseconds (cumulative count 7740)
..........
Cumulative distribution of latencies:
29.540% <= 0.103 milliseconds (cumulative count 2954)
99.810% <= 0.207 milliseconds (cumulative count 9981)
99.990% <= 0.303 milliseconds (cumulative count 9999)
100.000% <= 0.407 milliseconds (cumulative count 10000)
Summary:
throughput summary: 91743.12 requests per second
latency summary (msec):
avg min p50 p95 p99 max
0.121 0.032 0.127 0.167 0.183 0.319
|
For more options and examples, use:
Conclusion
In this guide, we have managed to install and configure Redis 6 on an Ubuntu server.