{"id":1926,"date":"2016-06-24T18:10:36","date_gmt":"2016-06-24T09:10:36","guid":{"rendered":"http:\/\/avinton.com\/?page_id=1926"},"modified":"2024-10-03T10:46:13","modified_gmt":"2024-10-03T01:46:13","slug":"redis","status":"publish","type":"page","link":"https:\/\/avinton.com\/en\/academy\/redis\/","title":{"rendered":"REDIS"},"content":{"rendered":"<div class=\"wpb-content-wrapper\"><p>[vc_row][vc_column][vc_column_text]<\/p>\n<h1>REDIS<\/h1>\n<h2>REDIS is an in-memory database.<\/h2>\n<p>It is not a replacement for a traditional RDBMS like MySQL, Oracle &amp; PostgreSQL.<br \/>\nREDIS works as a key value store &#8211; we will learn more about what this means from the exercises below.<\/p>\n<p>&nbsp;<\/p>\n<p>REDIS is typically used in cases where we need fast data indexing, data access or multiple simultaneous data reads \/ writes (it handles concurrency very well).<\/p>\n<p>REDIS is well documented here:<br \/>\n<a href=\"http:\/\/redis.io\/documentation\">http:\/\/redis.io\/documentation<\/a><\/p>\n<p>Command Reference:<br \/>\n<a href=\"http:\/\/redis.io\/commands\">http:\/\/redis.io\/commands<\/a><\/p>\n<p>&nbsp;<\/p>\n<h3>Install Redis on Ubuntu:<\/h3>\n<pre class=\"\">wget http:\/\/download.redis.io\/redis-stable.tar.gz\r\ntar xvzf redis-stable.tar.gz\r\ncd redis-stable\r\nmake\r\nsudo make install\r\nmake test\r\nsudo mkdir \/etc\/redis\r\nsudo mkdir \/var\/redis\r\nsudo cp utils\/redis_init_script \/etc\/init.d\/redis_6379\r\nsudo cp redis.conf \/etc\/redis\/6379.conf\r\nsudo mkdir \/var\/redis\/6379\r\nsudo vi \/etc\/redis\/6379.conf<\/pre>\n<p>In the configuration file make the following settings:<\/p>\n<p>Set daemonize to yes (by default it is set to no).<br \/>\nSet the pidfile to \/var\/run\/redis_6379.pid (modify the port if needed).<br \/>\nChange the port accordingly. In our example it is not needed as the default port is already 6379.<br \/>\nSet your preferred loglevel.<br \/>\nSet the logfile to \/var\/log\/redis_6379.log<br \/>\nSet the dir to \/var\/redis\/6379 (very important step!)<\/p>\n<p>&nbsp;<\/p>\n<pre class=\"\">sudo update-rc.d redis_6379 defaults\r\nredis-cli save<\/pre>\n<p>check the file if it was created in: \/var\/redis\/6379\/dump.rdb<\/p>\n<p>Now lets play with Redis remotely from a GUI client Ubuntu-Desktop:<\/p>\n<h4>On Ubuntu VM Configure Redis for remote connection<\/h4>\n<pre class=\"\">sudo vi \/etc\/redis\/6379.conf<\/pre>\n<p>&nbsp;<\/p>\n<p>Add the following line:<br \/>\n(This allows us to connect to the Redis server from a remote machine)<\/p>\n<pre class=\"\">bind 0.0.0.0<\/pre>\n<p>&nbsp;<\/p>\n<h3>Restart Redis<\/h3>\n<pre style=\"font-family: Consolas,Liberation Mono,Menlo,Courier,monospace; font-size: 11.9px; margin-top: 0px; font-stretch: normal; line-height: 1.45; word-wrap: normal; padding: 16px; overflow: auto; border-radius: 3px; margin-bottom: 0px!important; background-color: #f7f7f7;\"><code style=\"font-family: Consolas,Liberation Mono,Menlo,Courier,monospace; font-size: 11.9px; padding: 0px; margin: 0px; border-radius: 3px; word-break: normal; border: 0px; display: inline; overflow: visible; line-height: inherit; word-wrap: normal; background: transparent;\">sudo service redis_6379 stop\r\nsudo service redis_6379 start<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>Check Ubuntu VM IP address.<\/p>\n<pre class=\"\">ifconfig<\/pre>\n<p>&nbsp;<\/p>\n<h3>Install Redis Desktop<\/h3>\n<p>Download and install Redis Desktop on your MAC or PC:<br \/>\n<a href=\"http:\/\/redisdesktop.com\/download\">http:\/\/redisdesktop.com\/download<\/a><\/p>\n<p>&nbsp;<\/p>\n<p>Configure Redis connection in Redis Desktop using this ip address<br \/>\n&#8220;Connect to Redis Server&#8221;<\/p>\n<p>Enter IP address from Ubuntu<\/p>\n<p>Test Connection<\/p>\n<p>If this doesn&#8217;t work try setting your virtual machine network settings to Bridged mode in VMWare \/ VirtualBox<\/p>\n<h4>Try these exercises in the Redis Desktop application to learn about Redis<\/h4>\n<p>&nbsp;<\/p>\n<p>You can open Redis Desktop, connect to the Ubuntu Redis server and run the commands in the console.<\/p>\n<p>&nbsp;<\/p>\n<h3>String<\/h3>\n<p>Redis string is a sequence of bytes. Strings in Redis are binary safe, meaning they have a known length not determined by any special terminating characters, so you can store anything up to 512 megabytes in one string.<\/p>\n<pre class=\"\">SET kaisha_name \"Avinton\"\r\nGET kaisha_name<\/pre>\n<p>&nbsp;<\/p>\n<h3>Substring:<\/h3>\n<pre class=\"\">GETRANGE kaisha_name 2 3<\/pre>\n<p>&nbsp;<\/p>\n<h3>SET<\/h3>\n<p>SET new value and GET old value<\/p>\n<pre class=\"\">GETSET kaisha_name \"Avinton Japan KK\"<\/pre>\n<p>&nbsp;<\/p>\n<h3>MGET<\/h3>\n<p>Get multiple values at the same time<\/p>\n<pre class=\"\">SET project z\r\nMGET project kaisha_name<\/pre>\n<p>&nbsp;<\/p>\n<h3>SETEX<\/h3>\n<p>Set a key with expiry timer<\/p>\n<pre class=\"\">SETEX expired_key 10 expire<\/pre>\n<p>&nbsp;<\/p>\n<h3>Expiry TTL<\/h3>\n<p>To check how much life it has left before it dies:<\/p>\n<pre class=\"\">TTL expired_key<\/pre>\n<p>&nbsp;<\/p>\n<h3>Hash HMSET<\/h3>\n<p>A Redis hash is a collection of key value pairs. Redis Hashes are maps between string fields and string values, so they are used to represent objects<\/p>\n<pre class=\"\">HMSET kaisha:1 kaisha_name avinton kaisha_type KK employees 70\r\nHGETALL kaisha:1<\/pre>\n<p>&nbsp;<\/p>\n<h3>Lists LPUSH LRANGE<\/h3>\n<p>Redis Lists are simply lists of strings, sorted by insertion order. You can add elements to a Redis List on the head or on the tail.<\/p>\n<pre class=\"\">lpush training linux\r\nlpush training postgresq\r\nlpush training redis\r\nlpush training memory\r\nlpush training cpu\r\nlpush training gpu<\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"\">lrange training 2 3<\/pre>\n<p>&nbsp;<\/p>\n<h3>Sets SADD SMEMBERS<\/h3>\n<p>Redis Sets are an unordered collection of Strings. In redis you can add, remove, and test for existence of members in O(1) time complexity.<\/p>\n<pre class=\"\">sadd avinton gibo-san\r\nsadd avinton misaki-san\r\nsadd avinton fukushima-san\r\nsadd avinton sato-san\r\nsadd avinton takahara-san<\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"\">smembers avinton<\/pre>\n<p>&nbsp;<\/p>\n<h3>Sorted Sets ZADD ZRANGEBYSCORE<\/h3>\n<p>Redis Sorted Sets are, similarly to Redis Sets, non repeating collections of Strings. The difference is that every member of a Sorted Set is associated with score, that is used in order to take the sorted set ordered, from the smallest to the greatest score. While members are unique, scores may be repeated.<\/p>\n<pre class=\"\">zadd avintonSS 0 redis\r\nzadd avintonSS 1 postgresql\r\nzadd avintonSS 2 linux\r\nzadd avintonSS 2 python\r\nzadd avintonSS 1 cpu<\/pre>\n<pre class=\"\">ZRANGEBYSCORE avintonSS 2 2<\/pre>\n<p>&nbsp;<\/p>\n<h2>Conclusion<\/h2>\n<p>Above we have seen some examples of how to use REDIS.<\/p>\n<p>This gives us an idea about REDIS&#8217; flexibility despite being a &#8220;simple&#8221; key value store.<br \/>\nWe will choose from these different types (string, sets, lists, sorted sets and Hashes etc based on the data we want to store.[\/vc_column_text][\/vc_column][\/vc_row]<\/p>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>[vc_row][vc_column][vc_column_text] REDIS REDIS is an in-memory database. It is not a replacement for a traditional RDBMS like MySQL, Oracle &amp; PostgreSQL. REDIS works as a key value store &#8211; we will learn more about what this means from the exercises below. &nbsp; REDIS is typically used in cases where we need fast data indexing, data<br \/><a href=\"https:\/\/avinton.com\/en\/academy\/redis\/\" class=\"more\">Read more<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"parent":1906,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-1926","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.8 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>REDIS - Avinton Japan<\/title>\n<meta name=\"description\" content=\"REDIS REDIS is an in-memory database. It is not a replacement for a traditional RDBMS like MySQL, Oracle &amp; PostgreSQL. REDIS works as a key value\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/avinton.com\/en\/academy\/redis\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"REDIS - Avinton Japan\" \/>\n<meta property=\"og:description\" content=\"REDIS REDIS is an in-memory database. It is not a replacement for a traditional RDBMS like MySQL, Oracle &amp; PostgreSQL. REDIS works as a key value\" \/>\n<meta property=\"og:url\" content=\"https:\/\/avinton.com\/en\/academy\/redis\/\" \/>\n<meta property=\"og:site_name\" content=\"Avinton Japan\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/Avintons\/\" \/>\n<meta property=\"article:modified_time\" content=\"2024-10-03T01:46:13+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/avinton.com\/wp-content\/uploads\/2020\/02\/avinton-japan-big-data.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"630\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:site\" content=\"@AvintonJapan\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/avinton.com\/en\/academy\/redis\/\",\"url\":\"https:\/\/avinton.com\/en\/academy\/redis\/\",\"name\":\"REDIS - Avinton Japan\",\"isPartOf\":{\"@id\":\"https:\/\/avinton.com\/en\/#website\"},\"datePublished\":\"2016-06-24T09:10:36+00:00\",\"dateModified\":\"2024-10-03T01:46:13+00:00\",\"description\":\"REDIS REDIS is an in-memory database. It is not a replacement for a traditional RDBMS like MySQL, Oracle &amp; PostgreSQL. REDIS works as a key value\",\"breadcrumb\":{\"@id\":\"https:\/\/avinton.com\/en\/academy\/redis\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/avinton.com\/en\/academy\/redis\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/avinton.com\/en\/academy\/redis\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/avinton.com\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Avinton Academy\",\"item\":\"https:\/\/avinton.com\/en\/academy\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"REDIS\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/avinton.com\/en\/#website\",\"url\":\"https:\/\/avinton.com\/en\/\",\"name\":\"Avinton Japan\",\"description\":\"Tailored Solutions and Consulting in AI and Big Data\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/avinton.com\/en\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"REDIS - Avinton Japan","description":"REDIS REDIS is an in-memory database. It is not a replacement for a traditional RDBMS like MySQL, Oracle &amp; PostgreSQL. REDIS works as a key value","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/avinton.com\/en\/academy\/redis\/","og_locale":"en_US","og_type":"article","og_title":"REDIS - Avinton Japan","og_description":"REDIS REDIS is an in-memory database. It is not a replacement for a traditional RDBMS like MySQL, Oracle &amp; PostgreSQL. REDIS works as a key value","og_url":"https:\/\/avinton.com\/en\/academy\/redis\/","og_site_name":"Avinton Japan","article_publisher":"https:\/\/www.facebook.com\/Avintons\/","article_modified_time":"2024-10-03T01:46:13+00:00","og_image":[{"width":1200,"height":630,"url":"https:\/\/avinton.com\/wp-content\/uploads\/2020\/02\/avinton-japan-big-data.jpg","type":"image\/jpeg"}],"twitter_card":"summary_large_image","twitter_site":"@AvintonJapan","twitter_misc":{"Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/avinton.com\/en\/academy\/redis\/","url":"https:\/\/avinton.com\/en\/academy\/redis\/","name":"REDIS - Avinton Japan","isPartOf":{"@id":"https:\/\/avinton.com\/en\/#website"},"datePublished":"2016-06-24T09:10:36+00:00","dateModified":"2024-10-03T01:46:13+00:00","description":"REDIS REDIS is an in-memory database. It is not a replacement for a traditional RDBMS like MySQL, Oracle &amp; PostgreSQL. REDIS works as a key value","breadcrumb":{"@id":"https:\/\/avinton.com\/en\/academy\/redis\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/avinton.com\/en\/academy\/redis\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/avinton.com\/en\/academy\/redis\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/avinton.com\/en\/"},{"@type":"ListItem","position":2,"name":"Avinton Academy","item":"https:\/\/avinton.com\/en\/academy\/"},{"@type":"ListItem","position":3,"name":"REDIS"}]},{"@type":"WebSite","@id":"https:\/\/avinton.com\/en\/#website","url":"https:\/\/avinton.com\/en\/","name":"Avinton Japan","description":"Tailored Solutions and Consulting in AI and Big Data","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/avinton.com\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/avinton.com\/en\/wp-json\/wp\/v2\/pages\/1926","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/avinton.com\/en\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/avinton.com\/en\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/avinton.com\/en\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/avinton.com\/en\/wp-json\/wp\/v2\/comments?post=1926"}],"version-history":[{"count":13,"href":"https:\/\/avinton.com\/en\/wp-json\/wp\/v2\/pages\/1926\/revisions"}],"predecessor-version":[{"id":113695,"href":"https:\/\/avinton.com\/en\/wp-json\/wp\/v2\/pages\/1926\/revisions\/113695"}],"up":[{"embeddable":true,"href":"https:\/\/avinton.com\/en\/wp-json\/wp\/v2\/pages\/1906"}],"wp:attachment":[{"href":"https:\/\/avinton.com\/en\/wp-json\/wp\/v2\/media?parent=1926"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/avinton.com\/en\/wp-json\/wp\/v2\/categories?post=1926"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/avinton.com\/en\/wp-json\/wp\/v2\/tags?post=1926"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}