# Redis

<p><a href="https://redis.io/" >Redis</a> is an open source, in-memory data structure store. You can use it as a database and a message broker.</p>
<p>RudderStack stores all traits of your user as a <a href="https://redis.io/commands/hset" >Redis hash</a>, allowing you to access user profiles in real-time.</p>

<blockquote class="warning">
  <div class="tip-quote">
    
    <div class="tip-text"><p>Note that:</p>
<ul>
<li>This integration only accepts <a href="https://www.rudderstack.com/docs/event-spec/standard-events/identify/" >Identify</a> calls. RudderStack ignores all other event types.</li>
<li>It is highly recommended that you keep your Redis instance within a private network and make it accessible to RudderStack.</li>
</ul></div>
  </div>
</blockquote>
<p>Find the open source transformer code for this destination in the <a href="https://github.com/rudderlabs/rudder-transformer/tree/main/src/v0/destinations/redis" >GitHub repository</a>.</p>
<!-- end-chunk -->
<!-- begin-chunk -->
<h2 id="getting-started">Getting started</h2><ol>
<li>From your <a href="https://app.rudderstack.com/" >RudderStack dashboard</a>, add the source. Then, from the list of destinations, select <strong>Redis</strong>.</li>
<li>Assign a name to the destination and click <strong>Continue</strong>.</li>
</ol>
<!-- end-chunk -->
<!-- begin-chunk -->
<h3 id="connection-settings">Connection settings</h3><p>To successfully configure Redis as a destination, you will need to configure the following settings:</p>
<ul>
<li><strong>Address</strong>: Enter the address of your Redis instance.</li>
<li><strong>Password</strong>: Enter the password for your Redis instance.</li>
<li><strong>Database</strong>: Enter the database name of your Redis instance where RudderStack should store the user traits. You can use this setting to configure a different database in your Redis instance.</li>
<li><strong>Cluster Mode</strong>: Enable this setting if you&rsquo;re connecting to a Redis cluster within a multi-node RudderStack setup.</li>
</ul>

<blockquote class="warning">
  <div class="tip-quote">
    
    <div class="tip-text"><p>Note that if you enable <strong>Cluster Mode</strong>:</p>
<ul>
<li>You need to specify multiple host addresses in a comma separated format in the <strong>Address</strong> field.</li>
<li>RudderStack automatically disables the <strong>Database</strong> option.</li>
</ul></div>
  </div>
</blockquote>
<ul>
<li><strong>Secure</strong>: Enable this setting to secure the TLS communication between RudderStack Redis client and your Redis server.
<ul>
<li><strong>Skip verify</strong>: Enable this option to skip the client&rsquo;s verification of the server&rsquo;s certificate chain and host name. In this mode, TLS is susceptible to man-in-the-middle attacks. Use this option <strong>only</strong> for testing.</li>
<li><strong>CA certificate</strong>: Enter the certificate which needs to be verified while establishing a secure connection. Skip this setting if the Root CA of your server can be verified with any client, for example, Elasticache.</li>
</ul>
</li>
<li><strong>Prefix</strong>: By default, RudderStack stores user traits with the key <code>user:&lt;user_id&gt;</code>. You can specify an extra prefix to distinguish all RudderStack-stored keys.</li>
<li><strong>Consent management settings</strong>: Configure the consent management settings for the specified source by choosing the <strong>Consent management provider</strong> from the dropdown and entering the relevant consent category IDs. See <a href="https://www.rudderstack.com/docs/data-governance/consent-management/overview/" >Consent Management in RudderStack</a> for more information on this feature.</li>
</ul>
<!-- end-chunk -->
<!-- begin-chunk -->
<h2 id="identify">Identify</h2><p>You can use the <a href="https://www.rudderstack.com/docs/event-spec/standard-events/identify/" ><code>identify</code></a> call to identify a visiting user and associate them to their actions. It also lets you record the traits about them like their name, email address, etc.</p>
<p>RudderStack stores the user traits in the Redis instance configured in the <a href="#connection-settings" >connection settings</a>. You can access the latest user traits by querying Redis for the key <code>user:&lt;user_id&gt;</code>.</p>
<p>A sample <code>identify</code> call is shown below:</p>
<div class="rs-code">
  <div class="rs-code__head">javascript<button class="rs-code__copy" type="button">
      
      Copy
    </button>
  </div>
  <div class="highlight"><pre class="chroma"><code class="language-javascript" data-lang="javascript">// Identify a user with name and title as traits

rudderanalytics.identify(&#34;1hKOmRA4GRlm&#34;, {
  name: &#34;Alex Keener&#34;,
  title: &#34;CEO&#34;,
})</code></pre></div>
</div>

<blockquote class="warning">
  <div class="tip-quote">
    
    <div class="tip-text"><code>userId</code> is a required field for RudderStack to successfully send the <code>identify</code> events to Redis.</div>
  </div>
</blockquote>
<p>The following snippet highlights how it is stored in Redis:</p>
<div class="rs-code">
  <div class="rs-code__head">bash<button class="rs-code__copy" type="button">
      
      Copy
    </button>
  </div>
  <div class="highlight"><pre class="chroma"><code class="language-bash" data-lang="bash">// redis-cli
redis&gt; HGETALL user:1hKOmRA4GRlm
1) &#34;name&#34;
2) &#34;Alex Keener&#34;
3) &#34;title&#34;
4) &#34;CEO&#34;</code></pre></div>
</div>
<!-- end-chunk -->
<!-- begin-chunk -->
<h3 id="nested-properties">Nested properties</h3><p>If your user traits have nested properties, RudderStack flattens them with <code>.</code> as the separator.</p>
<p>Consider the following event:</p>
<div class="rs-code">
  <div class="rs-code__head">javascript<button class="rs-code__copy" type="button">
      
      Copy
    </button>
  </div>
  <div class="highlight"><pre class="chroma"><code class="language-javascript" data-lang="javascript">// Identify a user with location as a trait

rudderanalytics.identify(&#34;1hKOmRA4GRlm&#34;, {
  location: {
    state: &#34;Texas&#34;,
    city: &#34;Austin&#34;,
  },
})</code></pre></div>
</div>
<p>RudderStack flattens the properties as follows:</p>
<div class="rs-code">
  <div class="rs-code__head">bash<button class="rs-code__copy" type="button">
      
      Copy
    </button>
  </div>
  <div class="highlight"><pre class="chroma"><code class="language-bash" data-lang="bash">// redis-cli
redis&gt; HGETALL user:1hKOmRA4GRlm
1) &#34;location.state&#34;
2) &#34;Texas&#34;
3) &#34;location.city&#34;
4) &#34;Austin&#34;</code></pre></div>
</div>
<!-- end-chunk -->
<!-- begin-chunk -->
<h3 id="custom-prefix">Custom prefix</h3><p>If you specify a prefix while setting up your Redis destination, RudderStack uses it to prefix all the keys.</p>
<p>For example, if you specify the prefix <code>rudderstack</code> in the RudderStack dashboard setting and send the following call:</p>
<div class="rs-code">
  <div class="rs-code__head">javascript<button class="rs-code__copy" type="button">
      
      Copy
    </button>
  </div>
  <div class="highlight"><pre class="chroma"><code class="language-javascript" data-lang="javascript">// Identify a user with name and title as traits

rudderanalytics.identify(&#34;1hKOmRA4GRlm&#34;, {
  age: 23,
})</code></pre></div>
</div>
<p>The corresponding Redis CLI output is prefixed with <code>rudderstack</code> as shown below:</p>
<div class="rs-code">
  <div class="rs-code__head">bash<button class="rs-code__copy" type="button">
      
      Copy
    </button>
  </div>
  <div class="highlight"><pre class="chroma"><code class="language-bash" data-lang="bash">// redis-cli
redis&gt; HGETALL rudderstack:user:1hKOmRA4GRlm
1) &#34;age&#34;
2) 23</code></pre></div>
</div>
<!-- end-chunk -->
<!-- begin-chunk -->
<h3 id="delete-a-user">Delete a user</h3><p>You can delete a user in Redis using the <a href="https://www.rudderstack.com/docs/api/user-suppression-api/#adding-a-suppression-with-delete-regulation" >Suppression with Delete regulation</a> of the RudderStack <a href="https://www.rudderstack.com/docs/api/user-suppression-api/" >User Suppression API</a>.</p>

<blockquote class="warning">
  <div class="tip-quote">
    
    <div class="tip-text">While RudderStack forwards the deletion request, it <strong>does not guarantee</strong> deletion within a 30-day window. You will need to check with Redis if the request is fulfilled.</div>
  </div>
</blockquote>
<p>To delete a user, specify the <code>userId</code> in the event. A sample regulation request body for deleting a user in Redis is shown:</p>
<div class="rs-code">
  <div class="rs-code__head">json<button class="rs-code__copy" type="button">
      
      Copy
    </button>
  </div>
  <div class="highlight"><pre class="chroma"><code class="language-json" data-lang="json">{
  &#34;regulationType&#34;: &#34;suppress_with_delete&#34;,
  &#34;destinationIds&#34;: [&#34;2FIKkByqn37FhzczP23eZmURciA&#34;],
  &#34;users&#34;: [
    {
      &#34;userId&#34;: &#34;1hKOmRA4GRlm&#34;,
      &#34;&lt;customKey&gt;&#34;: &#34;&lt;customValue&gt;&#34;
    }
  ]
}</code></pre></div>
</div>
<!-- end-chunk -->
<!-- begin-chunk -->
<h2 id="faq">FAQ</h2><!-- end-chunk -->
<!-- begin-chunk -->
<h4 id="how-do-i-set-up-redis-on-docker-with-tls-support">How do I set up Redis on Docker with TLS support?</h4><p>To enable a TLS endpoint for accessing Redis, run a <code>redis-stunnel</code> container with a link to your Redis container and expose the TLS port. For more details, see <a href="https://hub.docker.com/r/runnable/redis-stunnel/" >redis-stunnel usage</a>.</p>

<html lang="en">
<blockquote class="info">
  <div class="tip-quote">
    
    <div class="tip-text"><ul>
<li>Set <strong>Common Name</strong> to <code>localhost</code> while generating the CA certificate and server certificates.</li>
<li>Set the TLS endpoint of the <code>redis-stunnel</code> container as the <strong>Address</strong> in your <a href="#connection-settings" >destination settings</a>.</li>
</ul>
</div>
  </div>
</blockquote>

</html>
<p>For example, see the following Redis destination settings:</p>

<figure class="image--main "  >
    <a 
         href="/docs/images/event-stream-destinations/redis-example-settings.webp"
        
        >
        <img src="/docs/images/event-stream-destinations/redis-example-settings.webp" 
         
         
         
        decoding="async" loading="lazy" class="img-shortcode"/>
    </a>
    
</figure>

<p>Here, <code>127.0.0.1:6380</code> is the address used while running containers locally with default values. You can specify the contents of the <a href="https://hub.docker.com/r/runnable/redis-stunnel/#:~:text=for%20accessing%20Redis.-,Usage,-The%20easiest%20setup" >generated <code>ca.pem</code> file</a> in the <strong>CA certificate</strong> field.</p>

