Redis is a free, open source key-value database. It is similar to memcached but the dataset is not volatile and other datatypes (such as lists and sets) are natively supported. Redis comes with redis-cli that provides a simple command-line interface to a Redis server. This tutorial walks you through how to install and configure Redis Server in Ubuntu. I tested this guide on Ubuntu 16.04 LTS server, however this guide is same for other Ubuntu/Debian-based distros.
Install Redis Server in Ubuntu
Redis Server is available in the default repositories of Ubuntu. So, you can install it using the apt-get package manager.
Run the following command to install Redis Server on your Ubuntu system:
sudo apt-get install redis-server
After installing, check if Redis Server is working or not with command:
sudo systemctl status redis-server
Sample output would be:
● redis-server.service - Advanced key-value store Loaded: loaded (/lib/systemd/system/redis-server.service; enabled; vendor pre Active: active (running) since Mon 2017-06-05 14:32:28 IST; 20s ago Docs: http://redis.io/documentation, man:redis-server(1) Main PID: 2531 (redis-server) CGroup: /system.slice/redis-server.service └─2531 /usr/bin/redis-server 127.0.0.1:6379 Jun 05 14:32:28 ubuntuserver systemd: Starting Advanced key-value store... Jun 05 14:32:28 ubuntuserver run-parts: run-parts: executing /etc/redis/re Jun 05 14:32:28 ubuntuserver run-parts: run-parts: executing /etc/redis/re Jun 05 14:32:28 ubuntuserver systemd: Started Advanced key-value store.
Just in case, if it is not started already, you can start it as shown below.
sudo systemctl enable redis-server
sudo systemctl start redis-server
To check the installed version of Redis Server, just run:
Redis server v=3.0.6 sha=00000000:0 malloc=jemalloc-3.6.0 bits=64 build=687a2a319020fa42
Configure Redis Server
The default configuration file of Redis is /etc/redis/redis.conf. By default Redis listens for connections from all the network interfaces available on the server. It is possible to listen to just one or multiple interfaces using the “bind” configuration directive, followed by one or more IP addresses.
To make Redis server to listen to a particular IP address, edit /etc/redis/redis.conf file:
sudo vi /etc/redis/redis.conf
Find the following line:
Change it as shown below.
To make it listen to multiple IP addresses, then change it like below.
bind 192.168.43.2 192.168.43.3
Save and close the file.
Restart Redis service to apply the changes.
sudo systemctl restart redis-server
Test Redis Server
Connect to the Redis Server using redis-cli from command line.
Now, you’re connected to your Redis server.
From here, you can run Redis commands to test its functionality. Let us see a simple example.
127.0.0.1:6379> set test "Welcome To LinuxMastersWiki" OK 127.0.0.1:6379> get test "Welcome To LinuxMastersWiki" 127.0.0.1:6379>
To quit from Redis command prompt, type exit.
For more details, refer the Redis official documentation page.
And, that’s all. If you find our guides useful, please share them on your social, professional networks and support Linux Masters Wiki. More good stuffs to come. Stay tuned.