How to Install and Configure Redis Server on Debian 9


Redis is a free, open source and high-performance in-memory data structure store that can be used as a database, cache, and message broker. Redis allows us to store information in the form of strings, hashes, lists, sets, sorted sets, bitmaps, geospatial indexes and hyperloglogs. Redis comes with redis-cli command line tool that provides a simple command-line interface to a Redis server. Redis also provides high availability via Redis Sentinel and automatic partitioning with Redis Cluster.


• Supports most POSIX systems like Linux, BSD, Mac OS X, and Solaris.
• Supports Pipelining of commands that allows you to use multiple values in a single command to speed up communication with the client libraries.
• Supports a lot of languages such as Java, JavaScript (Node.js), Julia, Lua, Objective-C, ActionScript, C, C++, C#, Clojure, Common Lisp, D, Dart and many more.
• Allows you to distribute the dataset across multiple Redis instances.
• Supports master-slave asynchronous replication and automatic failover.

In this tutorial, we are going to show you how to install, configure, and use Redis with Debian 9 on an Alibaba Cloud Elastic Compute Service (ECS) instance.


• A fresh Alibaba Cloud ECS instance with Debian 9 installed.
• A root password is setup on your server.

Getting Started

Before starting, you are recommended to update your system package repository with the latest version.

Run the following command to update your system repository:

apt-get update -y
apt-get upgrade -y

Next, install the required packages by running the following command:

Install Redis

You can install Redis server in two ways: install from Debian repository, or download Redis source, build, and install.

Install Redis from Repository

By default, Redis package is available in the Debian 9 repository. So you can easily install it by just running the following command:

Install Redis from Source

First, you will need to download the latest version of the Redis source from their official website:

After downloading, extract the downloaded source with the following command:

Next, change the directory to the Redis and compile Redis with the following command:

cd redis-stable

Once Redis is compiled, install Redis to your system with the following command:

Configure Redis

Next, you will need to configure Redis for development environment. So, create a directory structure for Redis:

mkdir /etc/redis
mkdir /var/redis

Next, create Redis user and group with the following command:

Next, give Redis group and user ownership to the redis directory:

chown redis:redis /var/redis
chmod 770 /var/redis

Next, copy Redis sample configuration file from Redis source directory to the directory you have created above:

Next, open Redis configuration file and make some changes as per your requirements:

Make the following changes:

##Default port to listen reids. You can also change it as per your need.
port 6379
## If you run Redis from upstart or systemd.
supervised systemd
##Path of the Redis log.
logfile /var/log/redis.log
##Location of the Redis data.
dir /var/redis/
##IP address to listen Redis on. You can also specify multiple IP address.

Save and close the file when you are finished.

Create Redis Systemd File

Next, you will need to create a systemd file to control and manage Redis daemon.

You can do this by creating redis.service file:

Add the following lines:

Description=Redis In-Memory Data Store
ExecStart=/usr/local/bin/redis-server /etc/redis/redis.conf
ExecStop=/usr/local/bin/redis-cli shutdown

Save and close the file when you are finished. Then start Redis service with the following command:

Next, check the Redis service status, whether it is running or not:

If everything is going fine, you should see the following output:

● redis.service - Redis In-Memory Data Store
Loaded: loaded (/etc/systemd/system/redis.service; disabled; vendor preset: enabled)
Active: active (running) since Sat 2017-10-28 01:10:03 EDT; 1min 6s ago
Main PID: 1063 (redis-server)
Tasks: 4 (limit: 4915)
CGroup: /system.slice/redis.service
└─1063 /usr/local/bin/redis-server

Test Redis

Once all the configuration is done properly, it’s time to test if the whole Redis setup is working fine.

Redis comes with redis-cli tool to manage a Redis server. You can connect the Redis server using the following command:

Once you have entered Redis environment, you should see the following output:

You can now test the server connectivity using ping command:


You can also use echo command to echo a given string:

You should see the following output:

You can also store and retrieve any value with the following command:> set test "Redis is working"

Next, retrieve the stored value with the following command:

You should see the following output:

You can exit from the Redis shell any time with the following command:

You can also access and manage Redis server from remote machine, you will need to use -h option along with redis-cli command:

Note: is a Redis Server IP address.

Secure Redis Server

By default, Redis allows to connect any user without a password. Redis is designed to be accessed by trusted clients inside trusted environments. So you are recommended to secure your Redis server with a password. So any clients need to be authenticated before accessing the database.

To enable Redis password authentication, you will need to generate a password using sha256sum:

You should see the following output:

Next, open the Redis default configuration file:

Find the line “# requirepass foobared” and replace it with the following:

Save and close the file when you are finished. Then restart Redis service to apply these changes:

Now, connect to Redis server and test connectivity with ping command:

redis-cli> ping

You should see the following Authentication error:

You will need to authenticate Redis server before running any command inside Redis shell.

To authenticate Redis server, run the following command:

If everything is working fine, you should see the following output:

That’s it! You can now easily run any command inside Redis shell.


Follow me to keep abreast with the latest technology news, industry insights, and developer trends.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store