How to install Redis Server on Ubuntu 18.04

How to install Redis Server on Ubuntu 18.04

Introduction

The Remote Dictionary Server is best suited where the durability of data is not needed. It has the ability to store data, called a value, inside a key.

This data can then be retrieved only if we know the exact key used to store it. Due to the nature of the database design, typical use cases are as follows:

  • Session caching
  • Full page cache
  • Message queue applications
  • Leaderboards counting

Special Note: Large companies such as Twitter, Amazon, and Microsoft are using Redis.

In this tutorial, we show you how to install Redis server on Ubuntu 18.04.

Steps

Update System Packages

 $ sudo apt update && sudo apt upgrade

Install Redis Server Package

$ sudo apt install redis-server

You may want to supervise Redis service on your server. By default, the Redis server has disabled supervised interaction.

Enable Redis supervised interaction by editing its config file as follows.

$ sudo vim /etc/redis/redis.conf

Head on to superviseddirective section as shown below and change the status from “no”to “systemd” which is used in Ubuntu 18.04. This will allow you to manage Redis as a service i.e. start, restart and check the status

# If you run Redis from upstart or systemd, Redis can interact with your
# supervision tree. Options:
#   supervised no          - no supervision interaction
#   supervised upstart - signal upstart by putting Redis into SIGSTOP mode
#   supervised systemd - signal systemd by writing READY=1 to $NOTIFY_SOCKET
#   supervised auto        - detect upstart or systemd method based on
#                            UPSTART_JOB or NOTIFY_SOCKET environment variables# Note: these supervision methods only signal "process is ready."
#           They do not enable continuous liveness pings back to your supervisor.
supervised systemd

Save your changes and reload the redis service to adapt the new changes made on the configuration file.

$ sudo systemctl reload redis

Test Redis Server

The Redis service has now been successfully installed on your server. Now you need to test whether the service is running.

Check whether the Redis service is running:

 $ sudo systemctl status redis

The output should be similar as shown below.

● redis-server.service - Advanced key-value store
                 Loaded: loaded (/lib/systemd/system/redis-server.service; enabled; vendor preset: enabled)
                 Active: active (running) since Thu 2018-09-20 19:16:21 UTC; 1 day 1h ago
                   Docs: http://redis.io/documentation,
                         man:redis-server(1)
                Process: 5556 ExecStop=/bin/kill -s TERM $MAINPID (code=exited, status=0/SUCCESS)
                Process: 5560 ExecStart=/usr/bin/redis-server /etc/redis/redis.conf (code=exited, status=0/SUCCESS)
                Main PID: 5577 (redis-server)
                  Tasks: 4 (limit: 1152)
                 CGroup: /system.slice/redis-server.service
                         └─5577 /usr/bin/redis-server 127.0.0.1:6379
 
                Sep 20 19:16:21 ubuntu18 systemd[1]: Starting Advanced key-value store...
                Sep 20 19:16:21 ubuntu18 systemd[1]: redis-server.service: Can't open PID file           /var/run/redis/redis-server.pid (yet?) after start: No such file or di
                Sep 20 19:16:21 ubuntu18 systemd[1]: Started Advanced key-value store.
                lines 1-15/15 (END)

It should show you active (running) in the third line of the output starting with “Active”

Perform the following tests:

1. To test whether the server is working, connect to the server and do a ping test to check its availability.

$ redis-cli
$ 127.0.0.1:6379> ping  PONG

2. We set a random value to check whether the server will store the data persistently.

$ 127.0.0.1:6379> set greetings "Hello World!"  OK

3. To retrieve the value, we use the following command

$ 127.0.0.1:6379> get greetings  "Hello World!"

4. Exit the server and restart the Redis service. Then check whether the storage is persistent.

$ 127.0.0.1:6379> exit
$ sudo systemctl restart redis
$ redis-cli
$ 127.0.0.1:6379> get greetings  "Hello World!"

Conclusion

The Redis server is only accessible from localhost. It may be necessary to configure it to allow connections from other sources ( IP addresses ) and other required configurations. For more details check our tutorial –How To Configure Redis Server on Ubuntu 18.04

Check out these top 3 Linux hosting services

FastComet
$1.79 /mo
Starting price
Visit FastComet
Rating based on expert review
  • User Friendly
    4.7
  • Support
    5.0
  • Features
    4.8
  • Reliability
    4.5
  • Pricing
    5.0
Kamatera
$4.00 /mo
Starting price
Visit Kamatera
Rating based on expert review
  • User Friendly
    3.5
  • Support
    3.0
  • Features
    3.9
  • Reliability
    4.0
  • Pricing
    4.3
HostArmada
$2.49 /mo
Starting price
Visit HostArmada
Rating based on expert review
  • User Friendly
    4.5
  • Support
    4.5
  • Features
    4.5
  • Reliability
    4.5
  • Pricing
    4.0

How To Install MongoDB On Ubuntu 18.04

This tutorial will help you install MongoDB; a popular web server, on Ubuntu 18.
3 min read
David Malcom
David Malcom
Author

How to Create a Non-root User on Your Ubuntu 18.04 VPS or Dedicated Server

This guide shows you how to create a user on your Ubuntu 18.04 virtual server.
3 min read
Michael Levanduski
Michael Levanduski
Expert Hosting Writer & Tester

How to Install a Self-Signed SSL Certificate on Your Ubuntu 18.04 VPS or Dedicated Server

This how-to article will teach you how to create a self-signed SSL certificate o
3 min read
Michael Levanduski
Michael Levanduski
Expert Hosting Writer & Tester

How to Set Up Cron Jobs on Your Ubuntu 18.04 Dedicated Server or VPS

This guide shows webmasters and administrators how to set up cron jobs on your U
3 min read
Idan Cohen
Idan Cohen
Marketing Expert
HostAdvice.com provides professional web hosting reviews fully independent of any other entity. Our reviews are unbiased, honest, and apply the same evaluation standards to all those reviewed. While monetary compensation is received from a few of the companies listed on this site, compensation of services and products have no influence on the direction or conclusions of our reviews. Nor does the compensation influence our rankings for certain host companies. This compensation covers account purchasing costs, testing costs and royalties paid to reviewers.
Click to go to the top of the page
Go To Top