March 13, 2019
3 min Read
Edward S.
Redis (Remote Dictionary Server) is an open-source, in-memory database that is used as a cache and message broker. It is also known as a data structure server. What sets it apart from other main databases is its ability to store high-level data types (including maps, lists, sets and more), an easy-to-use interface, atomic manipulation of data and exceptional performance that one cannot find with other existing databases. That’s exactly why in this tutorial, we’ll show you how to install Redis on Ubuntu 18.04 to improve your VPS server!
As mentioned above, it is the performance and the exceptional features of Redis that make it better than traditional databases. The typical uses of Redis are:
Redis is present in the official package repository of Ubuntu. Remember, first you need to access your VPS using SSH. If you’re having trouble, check out our PuTTY tutorial. Let’s install Redis on Ubuntu:
In order to install Redis, you first need to update the APT repository cache of your Ubuntu. You can do that with the following command:
sudo apt update
Now, you can enter the command to install Redis. Enter the following string into the command line:
sudo apt install redis
Press y and then hit enter to continue.
In order to check if Redis is installed properly and working correctly, you can enter the command:
redis-cli --version
The output will display the version of the utility currently installed on your machine.
Once you complete the installation, you can check if the Redis is running. You can do this with the following command:
sudo systemctl status redis
In the output, locate Active: active (running).
If Redis hasn’t been started, you can launch it by entering the command:
sudo systemctl start redis-server
If Redis is already running and you want to stop it, you can use the command:
sudo systemctl stop redis
After this, you will see Active: inactive (dead) in the output of the first command in this section.
The default configuration of Redis is placed in /etc/redis/redis.conf. By default, the server listens for connections from all interfaces available on the server. You can make it listen to the interfaces of your choice, which can be one, or multiple interfaces depending on your needs. This can be done by using the bind configuration directive that would be followed by a single, or multiple IP addresses.
To instruct the Redis server to listen for a particular IP address, you need to edit the /etc/redis/redis.conf file. Open it with your prefered editor. We’ll use vi. We open the file with the following command:
sudo vi /etc/redis/redis.conf
Locate the line bind 127.0.0.1
Now, change the IP address by entering the values of the interfaces you want the redis server to listen for. For example:
bind 192.168.43.2
And if you want to add multiple IP addresses, simply separate them with a space like so:
bind 192.168.43.2 192.168.43.3
Here you need to enter the IP addresses of your own network.
However, if you want the server to listen to all the interfaces on the network, you can use the command:
bind 0.0.0.0
Once you are done with making changes, save and close the file. In vi you can do this by hitting : and executing wq. Then restart the Redis server to apply the changes. The command for restarting is:
sudo systemctl restart redis-server
There are different groups of commands in Redis which include:
Here we have mentioned a mix of some commands used in Redis:
Redis-server /path/redis.conf | Starts Redis with the particular configuration file |
Redis-cli | Opens the Redis prompt |
APPEND key value | Append a value to a key |
BITCOUNT key [start end] | Sets bit in a string |
SET key value | Set a value in the key |
EXPIRE key 120 | Expire the key in 120 seconds |
INCR key | Increment the value in the key |
KEYS pattern | Finds all the keys matching a particular pattern |
How to install Redis on Ubuntu? It’s easy! With the help of this tutorial you successfully added the utility to your arsenal and can start using it! We hope you put this powerful tool to good use!
LEAVE A REPLY