<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Muhammad Hasham</title>
    <description>The latest articles on DEV Community by Muhammad Hasham (@muhammadhasham).</description>
    <link>https://dev.to/muhammadhasham</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F81656%2Fac0310b3-13e6-4725-a9b9-e606188c7408.jpeg</url>
      <title>DEV Community: Muhammad Hasham</title>
      <link>https://dev.to/muhammadhasham</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/muhammadhasham"/>
    <language>en</language>
    <item>
      <title>What Every Developer Must Know About SSL and TLS</title>
      <dc:creator>Muhammad Hasham</dc:creator>
      <pubDate>Fri, 01 Nov 2019 09:25:03 +0000</pubDate>
      <link>https://dev.to/muhammadhasham/what-every-developer-must-know-about-ssl-and-tls-3580</link>
      <guid>https://dev.to/muhammadhasham/what-every-developer-must-know-about-ssl-and-tls-3580</guid>
      <description>&lt;p&gt;SSL and TLS are often confused as if they are the same thing. But the truth is that SSL is the predecessor to TLS. New versions of TLS came up over the years to enhance security and support advance algorithms. &lt;/p&gt;

&lt;h1&gt;
  
  
  History
&lt;/h1&gt;

&lt;p&gt;TLS was introduced back in 1999 as a new version of SSL 3.0. SSL died in 2014 due to the famous &lt;a href="https://en.wikipedia.org/wiki/POODLE"&gt;Poodle Attack&lt;/a&gt;. &lt;/p&gt;

&lt;h2&gt;
  
  
  Terminologies:
&lt;/h2&gt;

&lt;p&gt;People still use the terminology of SSL, despite of the fact that it is what TLS that is being used.&lt;/p&gt;

&lt;p&gt;The most important or the takeaway of this post if the mechanism of TLS Handshake that takes place between a client and a server.&lt;/p&gt;

&lt;p&gt;It is rather a complex concept if we observe under the hood, but let's discuss the general concept for brevity.&lt;/p&gt;

&lt;h2&gt;
  
  
  TLS Handshake:
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--V8EEvvcp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/wo4uvkwt81n84hxpgne5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--V8EEvvcp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/wo4uvkwt81n84hxpgne5.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is also knows as TLS negotiation, after this process is completed the communication starts between client and server.&lt;/p&gt;

&lt;p&gt;The first step is when client tries to initiate connection with server over network. Server in response sends a public key with an encrypted certificate (A certificate is a file that is digitally bind with a cryptographic key and signed by CA).The client has a list of valid certificates. The client verifies public key with certificates that it holds, if the public key is invalid and does not align with a certificate on client side the negotiation fails. If that succeeds, the client sends it back in encrypted form with the server's public key.&lt;/p&gt;

&lt;p&gt;After the negotiation is successful, client and server communicate over an encrypted channel.&lt;/p&gt;

&lt;p&gt;This is TLS handshake in general.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;THIS IS QUITE GENERAL OVERVIEW. THERE IS A TON OF DETAIL, BUT THIS IS TO BE KNOWN TO BE THE LEAST.&lt;/em&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Good luck with your dev journey and don’t forget to like and share&lt;/p&gt;

&lt;p&gt;Have any questions? just want to say 👋 @MohammadHasham_&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;em&gt;Originally published at muhammadhasham.com/blog&lt;/em&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Redis 101: Foundation and Core Concepts</title>
      <dc:creator>Muhammad Hasham</dc:creator>
      <pubDate>Mon, 14 Oct 2019 14:02:12 +0000</pubDate>
      <link>https://dev.to/muhammadhasham/redis-101-foundation-and-core-concepts-1cg6</link>
      <guid>https://dev.to/muhammadhasham/redis-101-foundation-and-core-concepts-1cg6</guid>
      <description>&lt;p&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jyRlUZMS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1200/1%2Ai1d88Q8NNrRv6kjf7Ssw4g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jyRlUZMS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1200/1%2Ai1d88Q8NNrRv6kjf7Ssw4g.png" alt="" title="Redis"&gt;&lt;/a&gt;&lt;br&gt;&lt;br&gt;&lt;/p&gt;

&lt;p&gt;Redis has been in the database game for quite a while now. The popularity has been increasing due to various factors that are discussed below. But before starting we should understand what is Redis actually.&lt;br&gt;
So as per the docs state&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Redis is an open source (BSD licensed), in-memory data structure  store, used as a database, cache and message broker.&lt;br&gt;
&lt;br&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zvM1zj2G--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/6016/1%2AlRAAu4ztCpoY0Iim9gJctg.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zvM1zj2G--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/6016/1%2AlRAAu4ztCpoY0Iim9gJctg.jpeg" alt="alt text" title="Photo by Ben White on Unsplash"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now to be honest, the definition is difficult to understand. But I am quite sure that by the end of this article you would comprehend it properly.&lt;/p&gt;

&lt;p&gt;Let’s start by understanding what are &lt;strong&gt;NoSQL Databases&lt;/strong&gt; in general. NoSQL databases are used to store data in any other format than rows and columns. These are widely used to store data that is non relational in nature.&lt;/p&gt;

&lt;p&gt;For example, consider two tables &lt;strong&gt;Person&lt;/strong&gt; and &lt;strong&gt;Mobile_Phones&lt;/strong&gt;, the two tables tend to have a relation (A person can have one or many mobile phones). So in scenarios where we need to relation among data SQL Databases are preferred.&lt;/p&gt;

&lt;p&gt;Consider another scenario where the data to be stored has entries for two schemas such as &lt;strong&gt;Furniture&lt;/strong&gt; and &lt;strong&gt;Mobile_Phones&lt;/strong&gt;. It is quite evident that there is no such relation in above data. So storing this type of data in NoSQL database may increase overall performance.&lt;/p&gt;

&lt;p&gt;Examples for relational databases consist of MySQL,PostgreSQL. On the other hand, MongoDB,Redis,Neo4j etc are examples for NoSQL databases.&lt;br&gt;
&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--y4iZizDq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1920/1%2AAbmNmFHTOmIUA1Vw_JFv_w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--y4iZizDq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1920/1%2AAbmNmFHTOmIUA1Vw_JFv_w.png" alt="alt text" title="Google Images"&gt;&lt;/a&gt;&lt;/p&gt;



&lt;p&gt;Redis has different data structures to store data. Let’s explore them one by one.&lt;/p&gt;
&lt;h2&gt;
  
  
  Strings
&lt;/h2&gt;

&lt;p&gt;This is the base type of all the types. Every single value can be stored as strings.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;SET&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="err"&gt;“&lt;/span&gt;&lt;span class="nx"&gt;fido&lt;/span&gt;&lt;span class="err"&gt;”&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We are storing the string as a key value pair.&lt;/p&gt;



&lt;h2&gt;
  
  
  Key-Value Pair
&lt;/h2&gt;

&lt;p&gt;The most easy and used data structure for Redis is storing string in key-value pair.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;
&lt;span class="nx"&gt;SET&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="err"&gt;“&lt;/span&gt;&lt;span class="nx"&gt;fido&lt;/span&gt;&lt;span class="err"&gt;”&lt;/span&gt;
&lt;span class="nx"&gt;GET&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;
&lt;span class="c1"&gt;// fido&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you are familiar with Javascript objects or Python dictionaries. You can think of it as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;fido&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;h2&gt;
  
  
  Lists
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--IzkM3-k---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/750/1%2AmMN5zxOZo1XjHNGgyirKxg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IzkM3-k---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/750/1%2AmMN5zxOZo1XjHNGgyirKxg.png" alt="alt text" title="Google Images"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Lists are actually lists of strings stored in a particular order. Lists are also good when we want just to create a collection of N items where usually we access just the top or bottom items, or when N is small. Because random access is slow and takes O(N) time to complete.&lt;/p&gt;

&lt;p&gt;Lists have several commands such as &lt;strong&gt;RPUSH, LPUSH, LLEN, LRANGE, LPOP, and RPOP&lt;/strong&gt;. These commands help to perform specific operations lists.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="err"&gt;#&lt;/span&gt; &lt;span class="nx"&gt;RPUSH&lt;/span&gt; &lt;span class="nx"&gt;puts&lt;/span&gt; &lt;span class="nx"&gt;the&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="nx"&gt;at&lt;/span&gt; &lt;span class="nx"&gt;the&lt;/span&gt; &lt;span class="nx"&gt;end&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;the&lt;/span&gt; &lt;span class="nx"&gt;list&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;span class="nx"&gt;RPUSH&lt;/span&gt; &lt;span class="nx"&gt;friends&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Alice&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="err"&gt;#&lt;/span&gt; &lt;span class="nx"&gt;LPUSH&lt;/span&gt; &lt;span class="nx"&gt;puts&lt;/span&gt; &lt;span class="nx"&gt;the&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="nx"&gt;at&lt;/span&gt; &lt;span class="nx"&gt;the&lt;/span&gt; &lt;span class="nx"&gt;start&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;the&lt;/span&gt; &lt;span class="nx"&gt;list&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;span class="nx"&gt;LPUSH&lt;/span&gt; &lt;span class="nx"&gt;friends&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Bob&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;p&gt;&lt;strong&gt;LRANGE&lt;/strong&gt; gives a subset of the list. It takes the index of the first element you want to retrieve as its first parameter and the index of the last element you want to retrieve as its second parameter.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;LRANGE&lt;/span&gt; &lt;span class="nx"&gt;friends&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;p&gt;&lt;strong&gt;LLEN&lt;/strong&gt; returns the length of linked list&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;LPUSH&lt;/span&gt; &lt;span class="nx"&gt;friends&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Alice&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="nx"&gt;LPUSH&lt;/span&gt; &lt;span class="nx"&gt;friends&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Bob&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="nx"&gt;LLEN&lt;/span&gt; &lt;span class="nx"&gt;friends&lt;/span&gt;  &lt;span class="err"&gt;#&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;p&gt;&lt;strong&gt;LPOP&lt;/strong&gt; and &lt;strong&gt;RPOP&lt;/strong&gt; removes (pops) elements from start and end respectively.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="err"&gt;#&lt;/span&gt; &lt;span class="nx"&gt;RPOP&lt;/span&gt; &lt;span class="nx"&gt;pops&lt;/span&gt; &lt;span class="nx"&gt;the&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="nx"&gt;the&lt;/span&gt; &lt;span class="nx"&gt;end&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;the&lt;/span&gt; &lt;span class="nx"&gt;list&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;span class="nx"&gt;RPOP&lt;/span&gt; &lt;span class="nx"&gt;friends&lt;/span&gt;
&lt;span class="err"&gt;#&lt;/span&gt; &lt;span class="nx"&gt;LPOP&lt;/span&gt; &lt;span class="nx"&gt;pops&lt;/span&gt; &lt;span class="nx"&gt;the&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="nx"&gt;at&lt;/span&gt; &lt;span class="nx"&gt;the&lt;/span&gt; &lt;span class="nx"&gt;start&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;the&lt;/span&gt; &lt;span class="nx"&gt;list&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;span class="nx"&gt;LPOP&lt;/span&gt; &lt;span class="nx"&gt;friends&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Bob&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;h2&gt;
  
  
  Sets
&lt;/h2&gt;

&lt;p&gt;Among differences between sets and lists is that sets store unique elements unlike lists.&lt;/p&gt;

&lt;p&gt;Sets are an unordered data collection. Sets perform fast iteration than lists across elements.&lt;/p&gt;

&lt;p&gt;Sets support complex operations like intersections, unions, and so forth, so this is a good data structure for using Redis in a “computational” manner, when you have data and you want to perform transformations on that data to obtain some output.&lt;/p&gt;

&lt;p&gt;In sets adding, removing and lookup for an element takes O(1) constant time.&lt;/p&gt;

&lt;p&gt;Small sets are encoded in a very efficient way.&lt;/p&gt;

&lt;p&gt;Among many commands for Sets we will discuss &lt;strong&gt;SADD, SREM, SISMEMBER, SMEMBERS&lt;/strong&gt;.&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;SADD&lt;/strong&gt; adds a member to a set&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;SADD&lt;/span&gt; &lt;span class="nx"&gt;superpowers&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;flight&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;p&gt;&lt;strong&gt;SREM&lt;/strong&gt; removes a member from a set&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;SREM&lt;/span&gt; &lt;span class="nx"&gt;superpowers&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;flight&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;p&gt;&lt;strong&gt;SISMEMBER&lt;/strong&gt; tests if the given value is in the set. It returns 1 if the value is there and 0 if it is not.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;SISMEMBER&lt;/span&gt; &lt;span class="nx"&gt;superpowers&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;flight&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;  &lt;span class="err"&gt;#&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="nx"&gt;SISMEMBER&lt;/span&gt; &lt;span class="nx"&gt;superpowers&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;height&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;  &lt;span class="err"&gt;#&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;p&gt;&lt;strong&gt;SMEMBERS&lt;/strong&gt; returns all elements from a set.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;SMEMBERS&lt;/span&gt; &lt;span class="nx"&gt;superpowers&lt;/span&gt; &lt;span class="err"&gt;#&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;flight&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;height&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;h2&gt;
  
  
  Sorted Sets
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Sorted sets are the only other data structures, besides lists, to maintain ordered elements.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Sorted sets are like more powerful lists where inserting, removing, or getting ranges from the the middle of the list is always fast. But they use more memory, and are O(log(N)) data structures.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ZADD&lt;/strong&gt; command is used to add all the specified members with the specified scores to the sorted set stored at key. &lt;strong&gt;ZRANGE&lt;/strong&gt; displays all elements within the set -1 indicates the last index of set.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;ZADD&lt;/span&gt; &lt;span class="nx"&gt;mycolorset&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="nx"&gt;white&lt;/span&gt;
&lt;span class="nx"&gt;ZADD&lt;/span&gt; &lt;span class="nx"&gt;mycolorset&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="nx"&gt;black&lt;/span&gt;
&lt;span class="nx"&gt;ZRANGE&lt;/span&gt; &lt;span class="nx"&gt;mycolorset&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;

&lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="nx"&gt;white&lt;/span&gt;
&lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="nx"&gt;black&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;p&gt;Suppose if we insert another element at index 2. The element placed at index 2 will be shifted to the next index and the new element would take the place.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;ZADD&lt;/span&gt; &lt;span class="nx"&gt;mycolorset&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="nx"&gt;yellow&lt;/span&gt;
&lt;span class="nx"&gt;ZRANGE&lt;/span&gt; &lt;span class="nx"&gt;mycolorset&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="nx"&gt;white&lt;/span&gt; 
&lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="nx"&gt;yellow&lt;/span&gt;
&lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="nx"&gt;black&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;br&gt;&lt;br&gt;
To remove an element, we can use ZREM as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;ZREM&lt;/span&gt; &lt;span class="nx"&gt;mycolorset&lt;/span&gt; &lt;span class="nx"&gt;yellow&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This would remove the element from the sorted set.&lt;br&gt;
&lt;br&gt;&lt;br&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Hashes
&lt;/h2&gt;

&lt;p&gt;Hashes are used to store collective information about something. Let’s discuss an example to get better understanding.&lt;/p&gt;

&lt;p&gt;They act as maps between the string fields and the string values. Hence, they are the perfect data type to represent objects.&lt;/p&gt;

&lt;p&gt;In Redis, every hash can store up to more than 4 billion field-value pairs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;HMSET&lt;/span&gt; &lt;span class="nx"&gt;person&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;John Doe&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; 
&lt;span class="nx"&gt;designation&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Backend Engineer&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;likes&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt; &lt;span class="nx"&gt;shares&lt;/span&gt; &lt;span class="mi"&gt;23&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above code snippet, we are using &lt;strong&gt;HMSET&lt;/strong&gt; to store a hash. As we can see there are different fields associated with &lt;strong&gt;person.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let’s retrieve all the data with &lt;strong&gt;HGETALL&lt;/strong&gt; as&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;HGETALL&lt;/span&gt; &lt;span class="nx"&gt;person&lt;/span&gt; 
&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;
&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nx"&gt;John&lt;/span&gt; &lt;span class="nx"&gt;Doe&lt;/span&gt;
&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nx"&gt;designation&lt;/span&gt;
&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nx"&gt;Backend&lt;/span&gt; &lt;span class="nx"&gt;Engineer&lt;/span&gt;
&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nx"&gt;Likes&lt;/span&gt;
&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;
&lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nx"&gt;shares&lt;/span&gt;
&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="mi"&gt;23&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;










&lt;p&gt;Now that we have covered the basic data types. Let’s discuss the use cases for Redis.&lt;/p&gt;

&lt;p&gt;Apart from it’s many use cases, there are some popular use cases for Redis such as&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Caching Layer Database&lt;/li&gt;
&lt;li&gt;Pub/Sub&lt;/li&gt;
&lt;li&gt;Get top analysis for something&lt;/li&gt;
&lt;li&gt;Message Queues&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let’s discuss each of them briefly,&lt;/p&gt;

&lt;h2&gt;
  
  
  Caching Layer Database:
&lt;/h2&gt;

&lt;p&gt;Redis being an in-memory store can be used as cache for storing user session or other relevant details. &lt;br&gt;
Redis is highly performant to read data, which is one of the reasons of using it as a caching layer database &lt;br&gt;
on top of the main database.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--e2sb2Y5l--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/756/1%2AJMiqEDklGtz5_L2mFB-zNg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--e2sb2Y5l--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/756/1%2AJMiqEDklGtz5_L2mFB-zNg.png" alt="alt text" title="Google Images"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Pub/Sub:
&lt;/h2&gt;

&lt;p&gt;Redis Pub/Sub implements the messaging system where the publishers sends the messages while the subscribers receive them.&lt;br&gt;
The link by which the messages are transferred is called channel.A subscriber can subscribe to multiple publishers bases on scenario.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;PUBLISH&lt;/span&gt; &lt;span class="nx"&gt;chat&lt;/span&gt; &lt;span class="err"&gt;“&lt;/span&gt;&lt;span class="nx"&gt;Hi&lt;/span&gt; &lt;span class="nx"&gt;there&lt;/span&gt;&lt;span class="err"&gt;”&lt;/span&gt;
&lt;span class="nx"&gt;SUBSCRIBE&lt;/span&gt; &lt;span class="nx"&gt;chat&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--SfEUVMFj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/731/1%2ASbYWnSywngh8z_UpM_FiEQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SfEUVMFj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/731/1%2ASbYWnSywngh8z_UpM_FiEQ.png" alt="alt text" title="Google Images"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Get top analysis for something:
&lt;/h2&gt;

&lt;p&gt;We can get top users, top trends or anything on edges. By edges, that means anything that lies on top or bottom of our list.&lt;br&gt;
For example suppose we have some users and they have some scores. So we can easily store this in a sorted set and query as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;ZRANGE&lt;/span&gt; &lt;span class="nx"&gt;user_scores&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt; &lt;span class="nx"&gt;WITHSCORES&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above query would return top 10 users with their scores respectively. In scenarios like this Redis is the go to database.&lt;br&gt;
&lt;br&gt;&lt;br&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Message Queues:
&lt;/h2&gt;

&lt;p&gt;Redis has the same concept of queues as in general programming. Message queues can be implemented with push and pop if there are multiple processes running.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--RPQGycPF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/600/1%2AWVxrzV6O4tAtipIV8p7PGA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--RPQGycPF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/600/1%2AWVxrzV6O4tAtipIV8p7PGA.png"&gt;&lt;/a&gt;&lt;br&gt;
&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;/p&gt;

&lt;p&gt;There are many libraries that provide ease and enhanced functionalities to work with Redis queues.&lt;/p&gt;




&lt;p&gt;This was a brief introduction to the world of Redis there is a lot to &lt;a href="https://redis.io/documentation"&gt;explore&lt;/a&gt;. I would highly recommend to give a shot to &lt;a href="https://try.redis.io/"&gt;this&lt;/a&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Good luck and don’t forget to like and share&lt;/p&gt;

&lt;p&gt;Have any questions? just want to say 👋 &lt;a href="https://twitter.com/MohammadHasham_"&gt;@MohammadHasham_&lt;/a&gt; &lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>redis</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>database</category>
    </item>
  </channel>
</rss>
