{"id":4248,"date":"2021-02-10T12:24:28","date_gmt":"2021-02-10T12:24:28","guid":{"rendered":"https:\/\/linuxways.net\/?p=4248"},"modified":"2021-02-10T12:27:47","modified_gmt":"2021-02-10T12:27:47","slug":"how-to-install-and-configure-redis-in-ubuntu-20-04","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/ubuntu\/how-to-install-and-configure-redis-in-ubuntu-20-04\/","title":{"rendered":"How to Install and Configure Redis in Ubuntu 20.04"},"content":{"rendered":"<p>Redis is a database caching service and an In-memory data structure storage. Meaning, the frequent request to the database is cached by Redis and served from the fastest memory RAM. It helps to reduce time delays and increase the performance of your application by accessing in microseconds. Data structures such as hashes, lists, sorted sets, strings, sets, are supported by Redis.<\/p>\n<p>Normally, some GB of RAM is allocated to Redis. When running the applications, the memory is occupied. To refresh the storage at Redis maxmemory policy is used. The following are supported maxmemory policy algorithms:-<\/p>\n<p><strong>volatile-lru<\/strong> : remove the (LRU) less recently used keys first which has an expire set<\/p>\n<p><strong>allkeys_lru<\/strong> : remove the less recently used keys first regardless of expire set<\/p>\n<p><strong>volatiel_random<\/strong> : Remove random key with an expire set<\/p>\n<p><strong>allkeys_random<\/strong> : Keys are removed randomly without expire set<\/p>\n<p><strong>volatile_ttl<\/strong> : Remove nearest expire time keys ie. having minor TTL value<\/p>\n<p><strong>noeviction<\/strong> : None of the keys are expired, just return write operation.<\/p>\n<p><strong>In this article, I\u2019m going to install the latest version of Redis service on Ubuntu 20.04 and configure it.<\/strong><\/p>\n<h2>Installation<\/h2>\n<p>To install Redis on Ubuntu first make your system up to date.<\/p>\n<pre>$ sudo apt update<\/pre>\n<p>When an update is completed, install Redis using the apt package manager,<\/p>\n<pre>$ sudo apt install redis -y<\/pre>\n<p>After the installation is completed, check the version,<\/p>\n<pre>$ redis-cli -v<\/pre>\n<p>Now, start the Redis server by entering the following command.<\/p>\n<pre>$ sudo systemctl start redis-server<\/pre>\n<p>Enable the service so that it automatically starts when the server reboots,<\/p>\n<pre>$ sudo systemctl enable redis-server<\/pre>\n<p>Also, check the status of Redis server,<\/p>\n<pre>$ sudo systemctl status redis-server<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"870\" height=\"439\" class=\"wp-image-4249\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-128.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-128.png 870w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-128-300x151.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-128-768x388.png 768w\" sizes=\"auto, (max-width: 870px) 100vw, 870px\" \/><\/p>\n<p>The default port for Redis is 6379 and listens on IPv4 localhost 127.0.0.1 as well as IPV6 loopback address. You can verify by executing the following command.<\/p>\n<pre>$ ss -ltn<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"866\" height=\"208\" class=\"wp-image-4250\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-129.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-129.png 866w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-129-300x72.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-129-768x184.png 768w\" sizes=\"auto, (max-width: 866px) 100vw, 866px\" \/><\/p>\n<h2>Configuring Redis<\/h2>\n<p>In the default installation of Redis, the configuration file is at <strong>\/etc\/redis\/redis.conf . <\/strong><\/p>\n<p>To apply max memory limit and policy, first open the configuration file.<\/p>\n<pre>$ vi \/etc\/redis\/redis.conf<\/pre>\n<p>You can add the following parameter in the file. For example, set memory limit to 2 GB. and noeviction maxmemory policy.<\/p>\n<pre>maxmemory 2gb<\/pre>\n<pre>maxmemory-policy noeviction<\/pre>\n<p>Similarly, to add password add following in the same configuration file,<\/p>\n<pre>requirepass YourPassword<\/pre>\n<p>Your file should look like,<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"773\" height=\"377\" class=\"wp-image-4251\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-130.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-130.png 773w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-130-300x146.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-130-768x375.png 768w\" sizes=\"auto, (max-width: 773px) 100vw, 773px\" \/><\/p>\n<p>Save the file and restart the Redis service.<\/p>\n<pre>$ sudo systemctl restart redis-server<\/pre>\n<p><em>Note: You can also change default port and bind address from the configuration file.<\/em><\/p>\n<h2>Redis CLI<\/h2>\n<p>Now, let\u2019s access Redis from its CLI. To login to Redis server just type,<\/p>\n<pre>$ redis-cli<\/pre>\n<pre>127.0.0.1:6379&gt;<\/pre>\n<p>Now use password to login. ( if you have setup )<\/p>\n<pre>12.0.0.1:6379&gt; auth YourPassword<\/pre>\n<p>Set name &#8216;office&#8217; and value &#8216;Pokhara&#8217;<\/p>\n<pre>127.0.0.1:6379&gt; set office Pokhara<\/pre>\n<p>Get the key from name<\/p>\n<pre>127.0.0.1:6379&gt; get office<\/pre>\n<p>See all the keys in Redis<\/p>\n<pre>127.0.0.1:6379&gt; keys *<\/pre>\n<p>See memory details<\/p>\n<pre>127.0.0.1:6379&gt; info memory<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"669\" height=\"550\" class=\"wp-image-4252\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-131.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-131.png 669w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/02\/word-image-131-300x247.png 300w\" sizes=\"auto, (max-width: 669px) 100vw, 669px\" \/><\/p>\n<p>Flush all the key<\/p>\n<pre>127.0.0.1:6379&gt; flushall<\/pre>\n<p>login to different Redis server hosts and non-default port. For Example 10.10.18.6 with default port 6380<\/p>\n<pre>$ redis-cli -h 10.10.18.6 -p 6380<\/pre>\n<h2>Conclusion<\/h2>\n<p>The article gives you the idea of installing and configuring the Redis server on Ubuntu 20.04. Hope you like the article.<\/p>","protected":false},"excerpt":{"rendered":"<p>Redis is a database caching service and an In-memory data structure storage. Meaning, the frequent request to the database is cached by Redis and served from the fastest&hellip;<\/p>","protected":false},"author":31,"featured_media":4253,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[189,100],"class_list":["post-4248","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ubuntu","tag-redis","tag-ubuntu-20-04"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/4248","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/31"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=4248"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/4248\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/4253"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=4248"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=4248"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=4248"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}