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
- Want info about best web hosting? Clicking this link can be of great help.