How To Install Redis on Ubuntu 22.04|20.04|18.04

ComputingPost
4 min readSep 18, 2022

In this tutorial, I’ll walk you through the steps to install Redis Server on Ubuntu 22.04|20.04|18.04 Linux system. Redis is an Open Source in-memory data structure store. Redis can be used as a database server, as a message broker or for caching data in memory for faster retrieval.

Redis supported data structures are:

  • Hashes
  • sets with range queries
  • Strings
  • sorted lists
  • Hyperloglogs
  • Bitmaps
  • Geospatial indexes e.t.c

For CentOS 8 / CentOS 7 / Fedora use:

Install Redis on Ubuntu 22.04|20.04|18.04

In this section, we will look at how to install the latest release of Redis on Ubuntu. You can check the version of Redis Server available on your Ubuntu 22.04|20.04|18.04 using the following command.

$ sudo apt update

$ sudo apt policy redis-server

redis-server:

Installed: (none)

Candidate: 5:5.0.7-2 500

Version table:

5:5.0.7-2 500

500 http://mirrors.digitalocean.com/ubuntu focal/universe amd64 Packages

Step 1: Update your server Package list

Ensure your system is updated before installing Redis

sudo apt update

Step 2: Install Redis on Ubuntu 22.04|20.04|18.04

Redis Server package is available on the Ubuntu upstream repository. After updating your system, install Redis by running the following commands in your terminal.

sudo apt -y install redis-server

If you would like to have a more recent version of Redis Server, you may opt to use PPA repository maintained by Redis Development.

sudo add-apt-repository ppa:redislabs/redis

sudo apt-get update

sudo apt-get install redis

If you don’t have add-apt-repository command on your system, check our previous guide:

  • How to Install add-apt-repository on Debian / Ubuntu

Confirm Redis Server version:

$ redis-server -v

Redis server v=6.2.6 sha=00000000:0 malloc=jemalloc-5.1.0 bits=64 build=9c9e426e2f96cc51

Step 3: Start Redis Service on Ubuntu 22.04|20.04|18.04

By default, Redis service should be started after installation. But you can start and enable the service to start on boot manually using the command:

sudo systemctl enable --now redis-server

Step 4: Enable network Listen for Redis Service

For network clients to connect to your Redis server, it needs the service to listen on a network IP Address.

Open the file /etc/redis/redis.conf with your favorite text editor

sudo vim /etc/redis/redis.conf

Then change line bind 127.0.0.1 to below:

bind 0.0.0.0

Restart redis service after making the change:

sudo systemctl restart redis-server

Step 5: Configure Redis Authentication — (Optional but recommended)

Configure Redis Authentication for clients to require AUTH before processing any other commands.

requirepass

Example:

requirepass oobaiY8BA

Step 6: Set Persistent Store for Recovery (Optional)

Set persistence mode by changing the appendonlyvalue to yes

appendonly yes

appendfilename "appendonly.aof"

Restart redis service after making the changes

sudo systemctl restart redis-server

Check redis service status:

$ 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 Sun 2018-12-23 03:42:41 PST; 1s ago

Docs: http://redis.io/documentation,

man:redis-server(1)

Process: 10444 ExecStop=/bin/kill -s TERM $MAINPID (code=exited, status=0/SUCCESS)

Process: 10447 ExecStart=/usr/bin/redis-server /etc/redis/redis.conf (code=exited, status=0/SUCCESS)

Main PID: 10469 (redis-server)

Tasks: 4 (limit: 2319)

CGroup: /system.slice/redis-server.service

`-10469 /usr/bin/redis-server 0.0.0.0:6379



Dec 23 03:42:40 ubuntu-01 systemd[1]: Starting Advanced key-value store...

Dec 23 03:42:41 ubuntu-01 systemd[1]: Started Advanced key-value store.

You can view the port and IP used by Redis service using the sscommand:

$ ss -tunelp | grep 6379

tcp LISTEN 0 128 0.0.0.0:6379 0.0.0.0:* uid:112 ino:52652 sk:40 <->

If you have an active firewall service, allow port 6379

sudo ufw allow 6379/tcp

Step 7: Test connection to Redis Server

Confirm that you can connect to redis locally:

$ redis-cli

127.0.0.1:6379>

Test authenticate:

127.0.0.1:6379> AUTH 

OK

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

127.0.0.1:6379> AUTH WrongPassword

(error) ERR invalid password

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

Server

redis_version:5.0.3

redis_git_sha1:00000000

redis_git_dirty:0

redis_build_id:45d60903d31a0894

redis_mode:standalone

os:Linux 4.15.0-38-generic x86_64

arch_bits:64

multiplexing_api:epoll

atomicvar_api:atomic-builtin

gcc_version:7.3.0

process_id:10469

run_id:1630ad8b0bb9b8b8f811aac4aa7cae1fee51951d

tcp_port:6379

uptime_in_seconds:290

uptime_in_days:0

hz:10

configured_hz:10

lru_clock:2061779

executable:/usr/bin/redis-server

config_file:/etc/redis/redis.conf

Step 8: Perform 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



# Sample output

................................................

====== LRANGE_500 (first 450 elements) ======

10000 requests completed in 0.62 seconds

15 parallel clients

3 bytes payload

keep alive: 1



99.66% <= 1 milliseconds

100.00% <= 1 milliseconds

16129.03 requests per second



====== LRANGE_600 (first 600 elements) ======

10000 requests completed in 0.81 seconds

15 parallel clients

3 bytes payload

keep alive: 1



99.66% <= 1 milliseconds

99.93% <= 2 milliseconds

99.97% <= 3 milliseconds

100.00% <= 3 milliseconds

12345.68 requests per second



====== MSET (10 keys) ======

10000 requests completed in 0.09 seconds

15 parallel clients

3 bytes payload

keep alive: 1



100.00% <= 0 milliseconds

111111.11 requests per second

For more options and examples, use:

$ redis-benchmark --help

You have successfully installed Redis on Ubuntu 22.04|20.04|18.04 Server or Workstation.

https://www.computingpost.com/how-to-install-redis-on-ubuntu-22-0420-0418-04/?feed_id=709&_unique_id=6326b19b549db

--

--

ComputingPost

ComputingPost — Linux Howtos, Tutorials, Guides, News, Tips and Tricks.