How to Install Redis Server in CentOS and Debian Based Systems

Redis is an open source, high-performance and flexible in-memory data structure store (key value format) – used as a database, cache and message broker. It is written in ANSI C and runs on most if not all Unix-like operating systems including Linux (recommended for deploying) without external dependencies.

Requirements:

In this tutorial, we will provide instructions on how to install a Redis Server from source (which is the recommended method) in Linux. We will also show how to configure, manage and secure Redis. Since Redis serves all data from memory, we strongly suggest using a high memory VPS Server with this guide.

3. After the Redis compilation the src directory inside the Redis distribution is populated with the different following executables that are part of Redis:

redis-server – redis server.

redis-sentinel – redis sentinel executable (monitoring and failover).

redis-cli – a CLI utility to interact with redis.

redis-benchmark – used to check redis performances.

redis-check-aof and redis-check-dump – useful in the rare event of corrupted data files.

Step 2: Configure Redis Server in Linux

4. Next, you need to configure redis for a development environment to be managed by the init system (systemd for the purpose of this tutorial). Start by creating the necessary directories for storing redis config files and your data:

$ sudo mkdir /etc/redis
$ sudo mkdir -p /var/redis/

4. Then copy the template redis configuration file provided, into the directory you created above.

$ sudo cp redis.conf /etc/redis/

5. Now open the configuration file and update a few settings as follows.

$ sudo vi /etc/redis/redis.conf

6. Next search for the following options, then change (or use) their default values according to your local environment needs.

9. Next, test if the whole redis setup is working fine. To interact with redis server, use the redis-cli command. After connecting to the server, try running a few commands.

$ redis-cli
Test connection to server using ping command:
127.0.0.1:6379> ping
Use the echo command to echo a given string:
127.0.0.1:6379> echo "Tecmint is testing Redis"
You can also set a key value using the set command like this:
127.0.0.1:6379> set mykey "Tecmint is testing Redis"
Now view the value of mykey:
127.0.0.1:6379> get mykey

10. Then close the connection with the exit command, and restart the redis server. Afterwards check if mykey is still stored on the server as shown below:

Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.