<?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: Alper Güven</title>
    <description>The latest articles on DEV Community by Alper Güven (@alperguven).</description>
    <link>https://dev.to/alperguven</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%2F498072%2F4f6e2f8f-debe-4c41-a4f2-bece367eddaa.jpg</url>
      <title>DEV Community: Alper Güven</title>
      <link>https://dev.to/alperguven</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/alperguven"/>
    <language>en</language>
    <item>
      <title>Create Redis Key - An NPM Package to Config &amp; Create Redis Keys</title>
      <dc:creator>Alper Güven</dc:creator>
      <pubDate>Fri, 26 Aug 2022 22:01:42 +0000</pubDate>
      <link>https://dev.to/alperguven/create-redis-key-an-npm-package-to-config-create-redis-keys-95d</link>
      <guid>https://dev.to/alperguven/create-redis-key-an-npm-package-to-config-create-redis-keys-95d</guid>
      <description>&lt;h3&gt;
  
  
  Overview of My Submission
&lt;/h3&gt;

&lt;p&gt;I created an NPM package named as &lt;code&gt;create-redis-key&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;A Redis key creation utility.&lt;/p&gt;

&lt;p&gt;Create &lt;code&gt;Redis Key Templates&lt;/code&gt;, which include parameters, using a nested config object &amp;amp; use your &lt;code&gt;Redis Key Template&lt;/code&gt; strings to create Redis Keys.&lt;/p&gt;

&lt;p&gt;I published &lt;a href="https://dev.to/alperguven/create-redis-key-easy-way-to-configure-all-your-redis-keys-in-one-place-14hh"&gt;an introduction post&lt;/a&gt; for the package on DEV.to!&lt;/p&gt;

&lt;p&gt;Explained my motivation for developing such package on the &lt;a href="https://dev.to/alperguven/create-redis-key-easy-way-to-configure-all-your-redis-keys-in-one-place-14hh#motivation"&gt;motivation section of my introduction post&lt;/a&gt; for the package.&lt;/p&gt;

&lt;p&gt;The code released under &lt;a href="https://choosealicense.com/licenses/mit/" rel="noopener noreferrer"&gt;MIT&lt;/a&gt; licence on GitHub.&lt;/p&gt;

&lt;h3&gt;
  
  
  Submission Category:
&lt;/h3&gt;

&lt;p&gt;Wacky Wildcards&lt;/p&gt;

&lt;h3&gt;
  
  
  [Optional: Video Explainer of My Project]
&lt;/h3&gt;

&lt;p&gt;None.&lt;/p&gt;

&lt;h3&gt;
  
  
  Language Used
&lt;/h3&gt;

&lt;p&gt;Typescript &amp;amp; NodeJS&lt;/p&gt;

&lt;h3&gt;
  
  
  Link to Code
&lt;/h3&gt;

&lt;p&gt;See &lt;code&gt;create-redis-key&lt;/code&gt; on GitHub.&lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://assets.dev.to/assets/github-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/alper-guven" rel="noopener noreferrer"&gt;
        alper-guven
      &lt;/a&gt; / &lt;a href="https://github.com/alper-guven/create-redis-key" rel="noopener noreferrer"&gt;
        create-redis-key
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      Redis key creation utility
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;Create Redis Key&lt;/h1&gt;
&lt;/div&gt;
&lt;p&gt;A Redis key creation utility.&lt;/p&gt;
&lt;p&gt;Create &lt;code&gt;Redis Key Templates&lt;/code&gt;, which include parameters, using a nested config object &amp;amp; use your &lt;code&gt;Redis Key Template&lt;/code&gt; strings to create Redis Keys.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;This package heavily uses &lt;a href="https://www.typescriptlang.org/docs/handbook/2/template-literal-types.html" rel="nofollow noopener noreferrer"&gt;Template Literal Types&lt;/a&gt; which is available since &lt;a href="https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-1.html" rel="nofollow noopener noreferrer"&gt;TypeScript 4.1&lt;/a&gt; so you need at least this version of Typescript for this package to properly work.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;a rel="noopener noreferrer nofollow" href="https://camo.githubusercontent.com/ba676146226576137cf6b7adbb104f3f0d0d9febae8935445676b0a059ee71b1/68747470733a2f2f696d672e736869656c64732e696f2f6e706d2f646d2f6372656174652d72656469732d6b65793f7374796c653d666f722d7468652d6261646765"&gt;&lt;img src="https://camo.githubusercontent.com/ba676146226576137cf6b7adbb104f3f0d0d9febae8935445676b0a059ee71b1/68747470733a2f2f696d672e736869656c64732e696f2f6e706d2f646d2f6372656174652d72656469732d6b65793f7374796c653d666f722d7468652d6261646765" alt="npm"&gt;&lt;/a&gt;&lt;/th&gt;
&lt;th&gt;&lt;a href="https://choosealicense.com/licenses/mit/" rel="nofollow noopener noreferrer"&gt;&lt;img src="https://camo.githubusercontent.com/9218332452902d9e542a100d0af126fd3174a116456614d2cf093546a13783db/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d677265656e2e7376673f7374796c653d666f722d7468652d6261646765" alt="MIT License"&gt;&lt;/a&gt;&lt;/th&gt;
&lt;th&gt;&lt;a href="https://www.buymeacoffee.com/alperguven" rel="nofollow noopener noreferrer"&gt;&lt;img src="https://camo.githubusercontent.com/9f44ce2dc3b3eecdd02598900866ffc518801df1932849703dae1e5ce5031070/68747470733a2f2f7777772e6275796d6561636f666665652e636f6d2f6173736574732f696d672f637573746f6d5f696d616765732f6f72616e67655f696d672e706e67" alt='"Buy Me A Coffee"'&gt;&lt;/a&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;/table&gt;&lt;/div&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Examples&lt;/h2&gt;
&lt;/div&gt;
&lt;p&gt;&lt;a href="https://stackblitz.com/edit/create-redis-key?file=src/index.ts&amp;amp;view=editor" rel="nofollow noopener noreferrer"&gt;See it on action (StackBlitz)&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Check &lt;a href="https://github.com/alper-guven/create-redis-key#usage" rel="noopener noreferrer"&gt;How to Use&lt;/a&gt; section to see explanations of usage options on examples.&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Sections&lt;/h2&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/alper-guven/create-redis-key#installation" rel="noopener noreferrer"&gt;Installation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/alper-guven/create-redis-key#how-it-works" rel="noopener noreferrer"&gt;How It Works&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/alper-guven/create-redis-key#usage" rel="noopener noreferrer"&gt;How to Use&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/alper-guven/create-redis-key#option-1-recommended" rel="noopener noreferrer"&gt;Option 1 (Recommended)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/alper-guven/create-redis-key#option-2" rel="noopener noreferrer"&gt;Option 2&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/alper-guven/create-redis-key#option-2" rel="noopener noreferrer"&gt;Option 3 (Basic)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/alper-guven/create-redis-key#documentation" rel="noopener noreferrer"&gt;Documentation&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/alper-guven/create-redis-key#documentation---terms" rel="noopener noreferrer"&gt;Terms&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/alper-guven/create-redis-key#documentation---functions" rel="noopener noreferrer"&gt;Functions&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/alper-guven/create-redis-key#faq" rel="noopener noreferrer"&gt;FAQ&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/alper-guven/create-redis-key#running-tests" rel="noopener noreferrer"&gt;Running Tests&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/alper-guven/create-redis-key#local-development" rel="noopener noreferrer"&gt;Local Development&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/alper-guven/create-redis-key#contributing" rel="noopener noreferrer"&gt;Contributing&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Installation&lt;/h2&gt;

&lt;/div&gt;
&lt;p&gt;Install &lt;a href="https://www.npmjs.com/package/create-redis-key" rel="nofollow noopener noreferrer"&gt;create-redis-key&lt;/a&gt; with npm&lt;/p&gt;
&lt;div class="highlight highlight-source-shell notranslate position-relative overflow-auto js-code-highlight"&gt;
&lt;pre&gt;  npm install create-redis-key&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Type definitions? Included!&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;How It Works&lt;/h2&gt;

&lt;/div&gt;
&lt;p&gt;Eventual purpose of this library is to create a &lt;code&gt;Redis Key&lt;/code&gt; (which is basically a string) using a template which we call in this library a &lt;code&gt;Redis Key Template&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;There is…&lt;/p&gt;
&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/alper-guven/create-redis-key" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;See &lt;a href="https://www.npmjs.com/package/create-redis-key" rel="noopener noreferrer"&gt;create-redis-key&lt;/a&gt; on NPM.&lt;/p&gt;


&lt;div class="crayons-card c-embed text-styles text-styles--secondary"&gt;
    &lt;div class="c-embed__content"&gt;
      &lt;div class="c-embed__body flex items-center justify-between"&gt;
        &lt;a href="https://www.npmjs.com/package/create-redis-key" rel="noopener noreferrer" class="c-link fw-bold flex items-center"&gt;
          &lt;span class="mr-2"&gt;npmjs.com&lt;/span&gt;
          

        &lt;/a&gt;
      &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;


&lt;h3&gt;
  
  
  Additional Resources / Info
&lt;/h3&gt;

&lt;p&gt;My package is well documented &amp;amp; tested. Ready for production use.&lt;/p&gt;

&lt;h3&gt;
  
  
  Collaborators
&lt;/h3&gt;

&lt;p&gt;&lt;a class="mentioned-user" href="https://dev.to/alperguven"&gt;@alperguven&lt;/a&gt;&lt;/p&gt;




&lt;ul&gt;
&lt;li&gt;&lt;em&gt;Check out &lt;a href="https://redis.io/docs/stack/get-started/clients/#high-level-client-libraries" rel="noopener noreferrer"&gt;Redis OM&lt;/a&gt;, client libraries for working with Redis as a multi-model database.&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Use &lt;a href="https://redis.info/redisinsight" rel="noopener noreferrer"&gt;RedisInsight&lt;/a&gt; to visualize your data in Redis.&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Sign up for a &lt;a href="https://redis.info/try-free-dev-to" rel="noopener noreferrer"&gt;free Redis database&lt;/a&gt;.&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>redishackathon</category>
    </item>
    <item>
      <title>Create Redis Key - Easy Way to Configure All Your Redis Keys In One Place</title>
      <dc:creator>Alper Güven</dc:creator>
      <pubDate>Fri, 26 Aug 2022 20:55:00 +0000</pubDate>
      <link>https://dev.to/alperguven/create-redis-key-easy-way-to-configure-all-your-redis-keys-in-one-place-14hh</link>
      <guid>https://dev.to/alperguven/create-redis-key-easy-way-to-configure-all-your-redis-keys-in-one-place-14hh</guid>
      <description>&lt;p&gt;Create Redis Key is an NPM package, a Redis key creation utility for NodeJS (most effective when used with Typescript).&lt;/p&gt;

&lt;h2&gt;
  
  
  Sections
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Motivation&lt;/li&gt;
&lt;li&gt;The Package&lt;/li&gt;
&lt;li&gt;How To Use&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Motivation
&lt;/h2&gt;

&lt;p&gt;You might be wondering "Why would I need a package to create a Redis key? Isn't it just a string?"&lt;/p&gt;

&lt;p&gt;Well, it is.&lt;/p&gt;

&lt;p&gt;But even if an individual key is a string, most of the time we use many of them. Cache this, cache that, Cache 'Em All!&lt;/p&gt;

&lt;p&gt;Have you ever had a backend app which utilizes Redis a primary database? &lt;/p&gt;

&lt;p&gt;I have one. A microservice which has many resources stored in Redis. It stores data that change in an expected time span, varying from less than a second to hours.&lt;/p&gt;

&lt;p&gt;There comes the critical part(s): whether it be caching or storing data, keys mostly &lt;strong&gt;share a template&lt;/strong&gt; &amp;amp; what makes individual keys different is that these keys &lt;strong&gt;include resource identifiers&lt;/strong&gt; as a part of them since they are trying to locate different resources. Also, if a resource belongs to another resource, it's &lt;strong&gt;key starts with the key of the resource it belongs to&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Let's take Instagram as an example.&lt;/p&gt;

&lt;p&gt;Simply we can store a user with id 1 at the key &lt;code&gt;users:1&lt;/code&gt;. Then it makes sense to store the user with id 2 at the key &lt;code&gt;users:2&lt;/code&gt; and it goes on.&lt;/p&gt;

&lt;p&gt;As we can see they share the template &lt;code&gt;users:%UserID%&lt;/code&gt; and the template includes a resource identifier.&lt;/p&gt;

&lt;p&gt;There are different kind of resources which belongs to a user like follows, followers, posts etc. We can store them at keys &lt;code&gt;users:%UserID%:follows&lt;/code&gt;, &lt;code&gt;users:%UserID%:followers&lt;/code&gt;, &lt;code&gt;users:%UserID%:posts&lt;/code&gt; which start with the key of the resource they belong to (&lt;code&gt;users:%UserID%&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;So, wouldn't it be nice if we had a way to easily manage all our keys?&lt;/p&gt;

&lt;p&gt;Introducing Create Redis Key.&lt;/p&gt;

&lt;h2&gt;
  
  
  Create Redis Key
&lt;/h2&gt;

&lt;p&gt;A Redis key creation utility.&lt;/p&gt;

&lt;p&gt;Create &lt;code&gt;Redis Key Templates&lt;/code&gt;, which include parameters, using a nested config object &amp;amp; use your &lt;code&gt;Redis Key Template&lt;/code&gt; strings to create Redis Keys.&lt;/p&gt;

&lt;p&gt;See &lt;a href="https://www.npmjs.com/package/create-redis-key" rel="noopener noreferrer"&gt;create-redis-key&lt;/a&gt; on NPM.&lt;/p&gt;

&lt;p&gt;See &lt;a href="https://github.com/alper-guven/create-redis-key" rel="noopener noreferrer"&gt;create-redis-key&lt;/a&gt; on GitHub.&lt;/p&gt;

&lt;h2&gt;
  
  
  Usage
&lt;/h2&gt;

&lt;p&gt;First of all, import needed functions as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;createRedisKeyParam&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;createRedisKeysMap&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;createRedisKey&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;create-redis-key&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;p&gt;Create a &lt;code&gt;Redis Keys Config&lt;/code&gt; object.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;You should write &lt;code&gt;as const&lt;/code&gt; at the end of the object for Typescript types to properly work.&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;redisKeysConfig&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;SCOPE_FIRST_PART&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[],&lt;/span&gt;

  &lt;span class="c1"&gt;// app-statuses&lt;/span&gt;
  &lt;span class="na"&gt;appStatus&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;app-statuses&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;

  &lt;span class="na"&gt;users&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;SCOPE_FIRST_PART&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;users&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;

    &lt;span class="c1"&gt;// users:online&lt;/span&gt;
    &lt;span class="na"&gt;online&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;online&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;

    &lt;span class="na"&gt;byID&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;SCOPE_FIRST_PART&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;by-id&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;createRedisKeyParam&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;UserID&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)],&lt;/span&gt;

      &lt;span class="na"&gt;feed&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;SCOPE_FIRST_PART&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;feed&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;

        &lt;span class="c1"&gt;// users:by-id:%UserID%:feed:following&lt;/span&gt;
        &lt;span class="na"&gt;following&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;following&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="c1"&gt;// users:by-id:%UserID%:feed:favorites&lt;/span&gt;
        &lt;span class="na"&gt;favorites&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;favorites&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
      &lt;span class="p"&gt;},&lt;/span&gt;

      &lt;span class="c1"&gt;// users:by-id:%UserID%:follows&lt;/span&gt;
      &lt;span class="na"&gt;follows&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;follows&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
      &lt;span class="c1"&gt;// users:by-id:%UserID%:followers&lt;/span&gt;
      &lt;span class="na"&gt;followers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;followers&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
      &lt;span class="na"&gt;posts&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;SCOPE_FIRST_PART&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;posts&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;

        &lt;span class="na"&gt;byID&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="na"&gt;SCOPE_FIRST_PART&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;by-id&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;createRedisKeyParam&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;PostID&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)],&lt;/span&gt;

          &lt;span class="c1"&gt;// users:by-id:%UserID%:posts:by-id:%PostID%:comments&lt;/span&gt;
          &lt;span class="na"&gt;comments&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;comments&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
          &lt;span class="c1"&gt;// users:by-id:%UserID%:posts:by-id:%PostID%:likes&lt;/span&gt;
          &lt;span class="na"&gt;likes&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;likes&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="p"&gt;},&lt;/span&gt;
      &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then create a &lt;code&gt;Redis Keys Templates Map&lt;/code&gt; using the config:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If you give an invalid config, return type will be &lt;code&gt;never&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;RedisKeysMap&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createRedisKeysMap&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;redisKeysConfig&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The resulting object will be this, which is a &lt;code&gt;Redis Keys Templates Map&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"appStatus"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"app-statuses"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"users"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"online"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"users:online"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"byID"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"feed"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="nl"&gt;"following"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"users:by-id:%UserID%:feed:following"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="nl"&gt;"favorites"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"users:by-id:%UserID%:feed:favorites"&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"follows"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"users:by-id:%UserID%:follows"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"followers"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"users:by-id:%UserID%:followers"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"posts"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="nl"&gt;"byID"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
                    &lt;/span&gt;&lt;span class="nl"&gt;"comments"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"users:by-id:%UserID%:posts:by-id:%PostID%:comments"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
                    &lt;/span&gt;&lt;span class="nl"&gt;"likes"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"users:by-id:%UserID%:posts:by-id:%PostID%:likes"&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can then use this map to create a Redis key when needed:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;You will get parameter suggestions on your IDE based on the &lt;code&gt;Redis Key Template&lt;/code&gt; you provided to &lt;code&gt;createRedisKey()&lt;/code&gt; function. &lt;/p&gt;

&lt;p&gt;All params on a &lt;code&gt;Redis Key Template&lt;/code&gt; are required. You will get type errors if you don't provide all of them.&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;likesOfPostRK&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createRedisKey&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;RedisKeysMap&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;users&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;byID&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;posts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;byID&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;likes&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;UserID&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;1234&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;PostID&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;9876&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can see the generated key by logging it to console:&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;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;likesOfPostRK&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The log will be:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;users&lt;/span&gt;:by-id:1234:posts:by-id:9876:likes
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And that's it. You can now use the generated key to read the resource from Redis.&lt;/p&gt;

&lt;p&gt;There is actually 3 ways you can use this library. If you liked the idea, you can check more options and documentation on &lt;a href="https://github.com/alper-guven/create-redis-key" rel="noopener noreferrer"&gt;create-redis-key&lt;/a&gt; on GitHub.&lt;/p&gt;

&lt;p&gt;I want to see your comments. Is this a useful way to do this? Is there any other widely adopted strategy that you have seen on projects you worked on previously? Do you find it easy to use? Would you like to implement it on your existing projects or use it on your future projects?&lt;/p&gt;

&lt;p&gt;Happy coding!&lt;/p&gt;

</description>
      <category>redis</category>
      <category>node</category>
      <category>typescript</category>
      <category>npm</category>
    </item>
  </channel>
</rss>
