<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Redis - TheCodeBuzz</title>
	<atom:link href="https://thecodebuzz.com/category/redis/feed/" rel="self" type="application/rss+xml" />
	<link>https://thecodebuzz.com</link>
	<description>Best Practices for Software Development</description>
	<lastBuildDate>Thu, 23 Nov 2023 14:05:55 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://thecodebuzz.com/wp-content/uploads/2022/11/cropped-android-chrome-512x512-1-1-51x51.jpg</url>
	<title>Redis - TheCodeBuzz</title>
	<link>https://thecodebuzz.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>StackExchange.Redis -To create a disconnected multiplexer, disable AbortOnConnectFail</title>
		<link>https://thecodebuzz.com/stackexchange-it-was-not-possible-to-connect-to-the-redis-servers-to-create-a-disconnected-multiplexer-disable-abortonconnectfail/</link>
					<comments>https://thecodebuzz.com/stackexchange-it-was-not-possible-to-connect-to-the-redis-servers-to-create-a-disconnected-multiplexer-disable-abortonconnectfail/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Tue, 18 Jan 2022 08:04:00 +0000</pubDate>
				<category><![CDATA[Redis]]></category>
		<category><![CDATA[abortconnect=false]]></category>
		<category><![CDATA[abortonconnectfail redis connection string]]></category>
		<category><![CDATA[connectionmultiplexer]]></category>
		<category><![CDATA[connectionmultiplexer net core]]></category>
		<category><![CDATA[connectionmultiplexer.connect c#]]></category>
		<category><![CDATA[it was not possible to connect to the redis server(s). connecttimeout]]></category>
		<category><![CDATA[stackexchange.redis multiple connections]]></category>
		<category><![CDATA[stackexchangeredis timeout]]></category>
		<guid isPermaLink="false">https://www.thecodebuzz.com/?p=20234</guid>

					<description><![CDATA[<p>It was not possible to connect to the redis server(s)to create a disconnected multiplexer Today in this article, we will cover below aspects, Issue Description Redis connection throws an error, It was not possible to connect to the redis server(s);&#160;to create a disconnected multiplexer, disable AbortOnConnectFail.at StackExchange.Redis.ConnectionMultiplexer.ConnectImpl(Func`1 multiplexerFactory, TextWriter log)at MyApp.Web.Redis.StackExchangeClientConnection..ctor(ProviderConfiguration configuration)at MyApp.Web.Data.GetInventoryData() Resolution I [&#8230;]</p>
<p>The post <a href="https://thecodebuzz.com/stackexchange-it-was-not-possible-to-connect-to-the-redis-servers-to-create-a-disconnected-multiplexer-disable-abortonconnectfail/">StackExchange.Redis -To create a disconnected multiplexer, disable AbortOnConnectFail</a> first appeared on <a href="https://thecodebuzz.com">TheCodeBuzz</a>.</p>]]></description>
										<content:encoded><![CDATA[<h1 class="wp-block-heading">It was not possible to connect to the redis server(s)to create a disconnected multiplexer</h1>



<p>Today in this article, we will cover below aspects,</p>



<div class="wp-block-aioseo-table-of-contents"><ul><li><a href="#aioseo-issue-description">Issue Description</a></li><li><a href="#aioseo-resolution">Resolution</a></li></ul></div>



<h2 class="wp-block-heading" id="aioseo-issue-description">Issue Description </h2>



<p></p>



<p>Redis connection throws an error, </p>



<p></p>



<p class="has-medium-font-size"><span class="has-inline-color has-vivid-red-color">It was not possible to connect to the redis server(s);&nbsp;<strong>to create a disconnected multiplexer, disable AbortOnConnectFail</strong>.<br>at StackExchange.Redis.ConnectionMultiplexer.ConnectImpl(Func`1 multiplexerFactory, TextWriter log)<br>at MyApp.Web.Redis.StackExchangeClientConnection..ctor(ProviderConfiguration configuration)<br>at MyApp.Web.Data.GetInventoryData()</span></p>



<p></p>



<h2 class="wp-block-heading" id="aioseo-resolution">Resolution</h2>



<p></p>



<p>I found the error is due to configuration settings required for a Redis connection being missing.</p>



<p></p>



<p>Before trying this fix, please make sure the Redis server is up and running. </p>



<p></p>



<p>It&#8217;s recommended that if you set&nbsp;<em><strong>abortConnect=false&nbsp;</strong></em>in your connection string. </p>



<p></p>



<p><strong><em>StackExchange.Redis</em></strong> has a setting called <strong><em>AbortOnConnectFail</em>&nbsp;</strong>which handles connectivity errors. </p>



<p></p>



<p>Please note that the default value for <em><strong>AbortOnConnectFail </strong></em>setting flag is &#8220;True&#8221;, meaning connection resiliency will not be in effect for any transient error like network bleep, etc. Due to this application&nbsp;<strong>will not</strong>&nbsp;re-connect automatically in some cases.</p>



<p></p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow"><p><strong><em>A</em></strong>s default behavior, <strong><em>Redis&nbsp;will auto-reconnect i</em></strong>f a network has any <strong><em>transient error</em></strong> occurs.</p></blockquote>



<p></p>



<p></p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow"><p>Transient erros are most common in Cloud enviornment due to shared resources.</p></blockquote>



<p></p>



<p>Setting <strong>abortConnect&nbsp;</strong>as <strong><em>false </em></strong>will resolve the issue and connection <strong><em>resiliency </em></strong>will be implemented.</p>



<p></p>



<p><strong>Note </strong>&#8211; when <em><strong>AbortOnConnectFail = false</strong></em> setting is used then a total<strong><em> </em></strong>of <strong>3 retry </strong>attempts during the initial connect will be performed. However, this setting can be customized as per need.</p>



<p></p>



<p></p>



<p>I was able to fix the error by using the below code for C# applicaiton</p>



<p></p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: csharp; highlight: [6]; title: ; notranslate">
            
               var configurationOptions = new ConfigurationOptions
                {
                    EndPoints = { $&quot;{Configuration.GetValue&lt;string&gt;(&quot;RedisCache:Host&quot;)}: 
                    {Configuration.GetValue&lt;int&gt;(&quot;RedisCache:Port&quot;)}&quot; },
                    Ssl = true,
                    AbortOnConnectFail = false,
                };

                var multiplexer = ConnectionMultiplexer.Connect(configurationOptions); ;
</pre></div>


<p></p>



<p><strong>Note </strong>: For <strong><em>Azure Redis,</em></strong> the <strong><em>cloud </em></strong>instance property is already set with <em><strong>abortConnect=false&nbsp;</strong></em> as the default behavior. </p>



<p>However, It may not be the case for other cloud providers.</p>



<p></p>



<p><strong>Reference</strong>:</p>



<p></p>



<ul class="has-medium-font-size wp-block-list"><li><a href="https://www.thecodebuzz.com/redis-cache-best-practices-development/" title="best practices for Redis cache managment " target="_blank" rel="noreferrer noopener"><em>Best practices for Redis cache managment</em> </a><span style="color: initial;"> </span></li></ul>



<ul class="has-medium-font-size wp-block-list"><li><em><a href="https://www.thecodebuzz.com/redis-dependency-injection-connectionmultiplexer-redis-cache-netcore-csharp/" title="Redis-Dependency Injection of the ConnectionMultiplexer – Best Practices" target="_blank" rel="noreferrer noopener">Redis-Dependency Injection of the ConnectionMultiplexer</a></em></li></ul>



<ul class="has-medium-font-size wp-block-list"><li><em><a href="http://redis.io/topics/rediscli" target="_blank" rel="noreferrer noopener">REDIS CLI COMMANDS</a></em></li></ul>



<p></p>



<p>That&#8217;s all! Happy coding!</p>



<p></p>



<p>Does this help you fix your issue? </p>



<p></p>



<p>Do you have any better solutions or suggestions? Please sound off your comments below.</p>



<hr>



<p class=""></p>



<p class="has-background" style="background-color:#b6d9ac;font-size:18px"><br>Please <strong><em>bookmark </em></strong>this page and <em><strong>share </strong></em>it with your friends.                                                    Please <a href="https://www.thecodebuzz.com/subscription/" target="_blank" rel="noreferrer noopener"><em><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color"><strong>Subscribe</strong> </mark></em></a>to the blog to receive notifications on freshly published (2025) best practices and guidelines for software design and development.</p>




<br>



<hr>



<p class=""></p>



<p></p>



<p></p>



<p></p>



<p></p>



<p></p><p>The post <a href="https://thecodebuzz.com/stackexchange-it-was-not-possible-to-connect-to-the-redis-servers-to-create-a-disconnected-multiplexer-disable-abortonconnectfail/">StackExchange.Redis -To create a disconnected multiplexer, disable AbortOnConnectFail</a> first appeared on <a href="https://thecodebuzz.com">TheCodeBuzz</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://thecodebuzz.com/stackexchange-it-was-not-possible-to-connect-to-the-redis-servers-to-create-a-disconnected-multiplexer-disable-abortonconnectfail/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Redis Cache Design and Best Practices for Development</title>
		<link>https://thecodebuzz.com/redis-cache-best-practices-development/</link>
					<comments>https://thecodebuzz.com/redis-cache-best-practices-development/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Mon, 03 Jan 2022 07:01:00 +0000</pubDate>
				<category><![CDATA[Redis]]></category>
		<category><![CDATA[aws redis best practices]]></category>
		<category><![CDATA[azure redis cache best practices]]></category>
		<category><![CDATA[redis cache example]]></category>
		<category><![CDATA[redis cache key naming convention]]></category>
		<category><![CDATA[redis cache tutorial]]></category>
		<category><![CDATA[redis cache-aside]]></category>
		<category><![CDATA[redis caching patterns]]></category>
		<category><![CDATA[redis configuration best practices]]></category>
		<category><![CDATA[redis design patterns]]></category>
		<category><![CDATA[redis distributed cache]]></category>
		<category><![CDATA[redis hash best practices]]></category>
		<category><![CDATA[redis security best practices]]></category>
		<category><![CDATA[redis system design]]></category>
		<category><![CDATA[redis write-through cacheredis best practices and performance tuning]]></category>
		<category><![CDATA[stackexchange redis best practices]]></category>
		<guid isPermaLink="false">https://www.thecodebuzz.com/?p=18770</guid>

					<description><![CDATA[<p>Redis Cache Best Practices for Development Today in this article we will see a few Redis Cache Design and Best Practices for Development to be considered while developing the application leveraging the Cache architecture. We will cover the below aspects in this article, Caching is a typical strategy for improving a system&#8217;s performance and scalability. [&#8230;]</p>
<p>The post <a href="https://thecodebuzz.com/redis-cache-best-practices-development/">Redis Cache Design and Best Practices for Development</a> first appeared on <a href="https://thecodebuzz.com">TheCodeBuzz</a>.</p>]]></description>
										<content:encoded><![CDATA[<h1 class="wp-block-heading"><strong>Redis Cache Best Practices for Development</strong></h1>



<figure class="wp-block-image size-large is-resized"><img fetchpriority="high" decoding="async" width="1024" height="717" src="https://www.thecodebuzz.com/wp-content/uploads/2021/12/redis-cache-best-practices-memory-management-1024x717.jpg" alt="Redis Cache Design and Best Practices" class="wp-image-19716" style="width:719px;height:503px" srcset="https://thecodebuzz.com/wp-content/uploads/2021/12/redis-cache-best-practices-memory-management-1024x717.jpg 1024w, https://thecodebuzz.com/wp-content/uploads/2021/12/redis-cache-best-practices-memory-management-300x210.jpg 300w, https://thecodebuzz.com/wp-content/uploads/2021/12/redis-cache-best-practices-memory-management-768x538.jpg 768w, https://thecodebuzz.com/wp-content/uploads/2021/12/redis-cache-best-practices-memory-management-1536x1075.jpg 1536w, https://thecodebuzz.com/wp-content/uploads/2021/12/redis-cache-best-practices-memory-management-743x520.jpg 743w, https://thecodebuzz.com/wp-content/uploads/2021/12/redis-cache-best-practices-memory-management.jpg 1693w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p>Today in this article we will see a few Redis Cache Design and Best Practices for Development to be considered while developing the application leveraging the Cache architecture. </p>



<p></p>



<p>We will cover the below aspects in this article,</p>



<p></p>



<div class="wp-block-aioseo-table-of-contents"><ul><li><a href="#aioseo-naming-convention-for-redis-key-and-namespace">Naming convention for Redis Key and Namespace</a></li><li><a href="#block-3a28214d-1b75-4391-928c-b4456fe12405">Size/Lenth of Redis Key and Namespace</a></li><li><a href="#aioseo-use-the-scan-vs-keys-command-guidelines">Use the SCAN Vs KEYS command guidelines</a></li><li><a href="#aioseo-redis-server-powerful-with-rich-query-pattern---use-lua-scripts">Redis server powerful with rich query pattern &#8211; Use Lua Scripts</a></li><li><a href="#aioseo-storing-the-data-on-the-server">Storing the data on the server</a></li><li><a href="#aioseo-cache-frequently-used-data">Cache frequently used data</a></li><li><a href="#aioseo-managing-concurrency-in-a-cache">Managing concurrency in a cache</a></li><li><a href="#aioseo-manage-key-expiration-in-redis-cache">Manage Key Expiration in Redis Cache</a></li><li><a href="#aioseo-redis---security-for-data">Redis &#8211; Security for Data</a></li></ul></div>



<p></p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p><strong><em>Caching </em></strong>is a typical strategy for improving a system&#8217;s <strong>performance </strong>and <strong>scalability</strong>. </p>



<p></p>



<p>Cache lets you temporarily copy frequently accessed data to fast storage near to the application. </p>



<p></p>



<p><strong><em>Caching </em></strong>helps increase response times for client applications by serving data more quickly(data storage is located closer to the application than the original source.)</p>
</blockquote>



<p></p>



<p>Cache plays a crucial part in the below aspects of application management,</p>



<p></p>



<ul class="wp-block-list">
<li>Performance</li>
</ul>



<ul class="wp-block-list">
<li>High Availability </li>
</ul>



<ul class="wp-block-list">
<li>Reduced downtime</li>
</ul>



<p></p>



<p>Let&#8217;s look at a few high-level guidelines and best practices for developing the application using the Cache architecture. </p>



<p> </p>



<h2 class="wp-block-heading" id="aioseo-naming-convention-for-redis-key-and-namespace"><strong>Naming convention for Redis Key and Namespace</strong></h2>



<p></p>



<p>It&#8217;s important to follow the basic<strong><em> naming conventions for Redis Key and Namespace</em></strong> upfront to avoid any issues with managing the data on the server.</p>



<p></p>



<p>Redis Cache server is most time used as a shared server across applications/projects and it is likely to contain more data with a similar format as the application grows in size with multiple use cases.</p>



<p></p>



<p>Redis cache is based on <strong><em>key-value pai</em></strong>r but <strong>with a curated data structure</strong> and as long as the<strong> key is unique</strong>, you are set to leverage all benefits of the data management.</p>



<p></p>



<pre class="wp-block-preformatted has-medium-font-size"> SET key value </pre>



<p></p>



<p></p>



<p>If all of your data has to be stored in a single database, please create a&nbsp;<em>namespace</em>&nbsp;with&nbsp;a <em>key prefix</em>. </p>



<p></p>



<p>Below is an <strong>example </strong>of a key naming pattern</p>



<p></p>



<pre class="wp-block-preformatted has-medium-font-size">// Set keys for Saving account 


SET Saving:key1 value
SET Saving:key2 value



// Set keys for Credit Account


SET Credit:key1 value
SET Credit:key2 value


// Set keys for Personal account 


SET Personal:key1 value
SET Personal:key2 value

</pre>



<p>The above pattern can be extended as required so that we get the benefit for the same key managed by different applications or domains or modules.</p>



<p></p>



<p>Like we can add additional identifiers like Bank of ABCD </p>



<p></p>



<div class="wp-block-group"><div class="wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow">
<pre class="wp-block-preformatted has-medium-font-size"><em>Set keys for Bank of ABCD with saving Account</em>


SET BOA:Saving:key1 value </pre>



<pre class="wp-block-preformatted has-medium-font-size">SET BOA:Saving:key2 value </pre>
</div></div>



<p></p>



<p></p>



<h2 class="wp-block-heading" id="block-3a28214d-1b75-4391-928c-b4456fe12405"><strong>Size/Lenth of Redis Key and Namespace</strong></h2>



<p></p>



<p>There are few Guidelines on Redis Key and Namespace </p>



<p></p>



<p>It is important to keep your Redis key names as short as possible. </p>



<p></p>



<p>Even shorter keys should follow the above namespace and key rules. </p>



<p></p>



<p>Any key above <strong><em>1024 bytes</em></strong> is not recommended as key size may cause issues considering memory and bandwidth. </p>



<p></p>



<ul class="has-medium-font-size wp-block-list">
<li><em>Redis key size max is 512 MB.</em></li>



<li><em>Redis Value size max is 512 MB.</em></li>
</ul>



<p></p>



<p>The Performance issue however is more observed when dealing with a high volume of data and which also depends on the Redis server configuration.</p>



<p></p>



<p></p>



<h2 class="wp-block-heading" id="aioseo-use-the-scan-vs-keys-command-guidelines"><strong>Use the SCAN Vs KEYS command guidelines</strong></h2>



<p></p>



<p><strong>KEY commands </strong></p>



<p></p>



<ul class="wp-block-list">
<li>KEYS command, which returns all matched elements at once, is risky to use in production.</li>
</ul>



<ul class="wp-block-list">
<li>It may cause your Redis server to become inefficient and even exhaust its RAM resources. </li>
</ul>



<p></p>



<p><strong>SCAN Commands</strong></p>



<p></p>



<ul class="wp-block-list">
<li>SCAN commands allow you to inspect data without risking your server being blocked.</li>
</ul>



<ul class="wp-block-list">
<li>SCAN command allows you to get the data without requiring the use of a slave. </li>
</ul>



<ul class="wp-block-list">
<li>The&nbsp;<a href="http://redis.io/commands/scan" target="_blank" rel="noreferrer noopener">SCAN</a>&nbsp;command enables you to retrieve keys in the keyspace using a cursor. </li>
</ul>



<ul class="wp-block-list">
<li>SCAN also accepts a key name pattern and an optional count argument. </li>
</ul>



<ul class="wp-block-list">
<li>The major difference between SCAN and KEYS is that it is possible to get the same key name more than once with SCAN.</li>
</ul>



<p></p>



<p></p>



<h2 class="wp-block-heading" id="aioseo-redis-server-powerful-with-rich-query-pattern---use-lua-scripts"><strong>Redis server powerful with rich query pattern &#8211; Use Lua Scripts</strong></h2>



<p></p>



<ul class="wp-block-list">
<li>Lua scripts on the Redis server make your query pattern very rich with great performance and less server-side resource consumption. </li>
</ul>



<ul class="wp-block-list">
<li>Server-side query/logics run near to actual data which reduces network latency and redundant transmission of data.</li>
</ul>



<p></p>



<h2 class="wp-block-heading" id="aioseo-storing-the-data-on-the-server"><strong>Storing the data on the server </strong></h2>



<p></p>



<p>There are multiple ways, data can be stored on the Redis server. Like as below,</p>



<p></p>



<ul class="wp-block-list">
<li><strong>Multiple Redis instances</strong></li>
</ul>



<ul class="wp-block-list">
<li><strong>Single Redis instances</strong></li>
</ul>



<p></p>



<h2 class="wp-block-heading" id="aioseo-cache-frequently-used-data"><strong>Cache frequently used data</strong></h2>



<p></p>



<ul class="wp-block-list">
<li>Determine data to be cached.</li>
</ul>



<ul class="wp-block-list">
<li>Cache your most frequently accessed data.</li>
</ul>



<ul class="wp-block-list">
<li>Cache critical or authoritative information only if needed with the right strategy.</li>
</ul>



<ul class="wp-block-list">
<li>Do restrict caching for frequently modified data.</li>
</ul>



<p></p>



<h2 class="wp-block-heading" id="aioseo-managing-concurrency-in-a-cache"><strong>Managing concurrency in a cache</strong></h2>



<p></p>



<p>Redis cache is designed to be shared by multiple instances of application/system. </p>



<p></p>



<p>However, one can follow any of the below approaches to make sure data is accessed considering the concurrency.</p>



<p></p>



<ul class="wp-block-list">
<li><strong>Optimistic</strong>&#8211; application checks if data in the cache has changed since it was retrieved. A useful approach when updates are infrequent.</li>
</ul>



<p></p>



<ul class="wp-block-list">
<li><strong>Pessimistic</strong>&#8211; When it retrieves the data, the application locks it in the cache to prevent another instance from changing it.</li>
</ul>



<p> </p>



<p></p>



<h2 class="wp-block-heading" id="aioseo-manage-key-expiration-in-redis-cache"><strong>Manage Key Expiration in Redis Cache</strong></h2>



<p></p>



<ul class="wp-block-list">
<li>Managing the key  Expiration is an important aspect while managing the keys in Reds cache.</li>
</ul>



<ul class="wp-block-list">
<li>Understand your datastore pattern.</li>
</ul>



<ul class="wp-block-list">
<li>Carefully check the data expiration. Too short Key expiration will make objects to expires sooner in Cache thereby increasing the call to your backend server also too long data will make you used stale old data producing issues.</li>
</ul>



<p></p>



<h2 class="wp-block-heading" id="aioseo-redis---security-for-data"><strong>Redis &#8211; Security for Data</strong></h2>



<p></p>



<ul class="wp-block-list">
<li>Redis does not allow data encryption natively, encoding must be done by client applications.</li>
</ul>



<ul class="wp-block-list">
<li>As Redis does not offer transport security by default, the use of an <strong><em>SSL proxy</em></strong> is recommended if you need to protect data as it travels across the network.</li>
</ul>



<ul class="wp-block-list">
<li>Redis is designed to run inside a trusted environment and data is accessed by only trusted clients.</li>
</ul>



<p></p>



<p></p>



<p><strong>Useful References: </strong></p>



<p></p>



<ul class="wp-block-list">
<li><a href="https://www.thecodebuzz.com/connection-resiliency-redis-cache-stackexchange-redi-best-practices/" target="_blank" rel="noreferrer noopener" title="Connection Resiliency for Redis Cache -Best Practices"><strong><em>Connection Resiliency for Redis Cache -Best Practices</em></strong></a></li>
</ul>



<p></p>



<p style="font-size:18px">Do you have any <strong>comments or ideas or any better </strong>suggestions to share?</p>



<p class="has-small-font-size"></p>



<p style="font-size:18px">Please sound off your comments below.</p>



<p class="has-medium-font-size"></p>



<p class="has-medium-font-size"><strong>Happy Coding </strong>!!</p>



<p></p>



<hr>



<p class=""></p>



<p class="has-background" style="background-color:#b6d9ac;font-size:18px"><br>Please <strong><em>bookmark </em></strong>this page and <em><strong>share </strong></em>it with your friends.                                                    Please <a href="https://www.thecodebuzz.com/subscription/" target="_blank" rel="noreferrer noopener"><em><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color"><strong>Subscribe</strong> </mark></em></a>to the blog to receive notifications on freshly published (2025) best practices and guidelines for software design and development.</p>




<br>



<hr>



<p class=""></p>



<p></p>



<p></p>



<p></p><p>The post <a href="https://thecodebuzz.com/redis-cache-best-practices-development/">Redis Cache Design and Best Practices for Development</a> first appeared on <a href="https://thecodebuzz.com">TheCodeBuzz</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://thecodebuzz.com/redis-cache-best-practices-development/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Redis Connect with SSL/TLS using C# .NET</title>
		<link>https://thecodebuzz.com/redis-connect-with-ssl-tls-using-csharp-asp-net-core/</link>
					<comments>https://thecodebuzz.com/redis-connect-with-ssl-tls-using-csharp-asp-net-core/#comments</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Tue, 21 Sep 2021 22:51:00 +0000</pubDate>
				<category><![CDATA[Redis]]></category>
		<category><![CDATA[Redis SSL connection]]></category>
		<guid isPermaLink="false">https://www.thecodebuzz.com/?p=18727</guid>

					<description><![CDATA[<p>Redis connect with SSL/TLS using C# .NET Today in this article we shall see how to enable Redis connect with SSL certificate using C# .NET application. Install StackExchange.Redis&#160; Please install the Redis NuGet package Microsoft.Extensions.Caching.StackExchangeRedis as below, PM>Install-Package Microsoft.Extensions.Caching.StackExchangeRedis -Version &#60;version> Or using .NET CLI dotnet add package Microsoft.Extensions.Caching.StackExchangeRedis --version 5.0.1 Console application with Redis [&#8230;]</p>
<p>The post <a href="https://thecodebuzz.com/redis-connect-with-ssl-tls-using-csharp-asp-net-core/">Redis Connect with SSL/TLS using C# .NET</a> first appeared on <a href="https://thecodebuzz.com">TheCodeBuzz</a>.</p>]]></description>
										<content:encoded><![CDATA[<h1 class="wp-block-heading" id="aioseo-redis-connect-with-ssl-using-c-net">Redis connect with SSL/TLS using C# .NET</h1>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="784" height="688" src="https://www.thecodebuzz.com/wp-content/uploads/2022/11/Redis-SSL.jpg" alt="" class="wp-image-24173" style="width:262px;height:230px" srcset="https://thecodebuzz.com/wp-content/uploads/2022/11/Redis-SSL.jpg 784w, https://thecodebuzz.com/wp-content/uploads/2022/11/Redis-SSL-300x263.jpg 300w, https://thecodebuzz.com/wp-content/uploads/2022/11/Redis-SSL-768x674.jpg 768w, https://thecodebuzz.com/wp-content/uploads/2022/11/Redis-SSL-593x520.jpg 593w" sizes="(max-width: 784px) 100vw, 784px" /></figure>



<p>Today in this article we shall see how to enable Redis connect with SSL certificate using C# .NET application.</p>



<p></p>



<h2 class="wp-block-heading" id="installing-stackexchangeredis">Install StackExchange.Redis&nbsp;</h2>



<p></p>



<p id="block-4161c405-d64c-4900-87b3-4bfcf3a14725">Please install the <strong><em>Redis </em></strong>NuGet package <a href="https://www.nuget.org/packages/Microsoft.Extensions.Caching.StackExchangeRedis/5.0.1" target="_blank" rel="noreferrer noopener">Microsoft.Extensions.Caching.StackExchangeRedis</a></p>



<p id="block-4161c405-d64c-4900-87b3-4bfcf3a14725"> as below,</p>



<p></p>



<pre class="wp-block-preformatted">PM>Install-Package<a href="https://www.nuget.org/packages/Microsoft.Extensions.Caching.StackExchangeRedis/5.0.1" target="_blank" rel="noreferrer noopener"> Microsoft.Extensions.Caching.StackExchangeRedis</a> -Version &lt;version>
</pre>



<p>Or using .NET CLI</p>



<p></p>



<pre class="wp-block-preformatted has-medium-font-size">dotnet add package Microsoft.Extensions.Caching.StackExchangeRedis --version 5.0.1</pre>



<p></p>



<h2 class="wp-block-heading" id="aioseo-console-application-with-redis-ssl"><strong>Console application with Redis SSL</strong></h2>



<p></p>



<pre class="wp-block-syntaxhighlighter-code">            var configurationOptions = new ConfigurationOptions
            {
                EndPoints = { "localhost:6379" },
                Ssl = true
            };

            configurationOptions.CertificateSelection += delegate {
                var cert = new X509Certificate2(PATH_TO_CERT_FILE, "");
                return cert;
            };


            var redis = await ConnectionMultiplexer.ConnectAsync(configurationOptions);
            Console.WriteLine(redis.GetDatabase().Ping());
        
    </pre>



<p></p>



<ul class="wp-block-list">
<li><strong><em>ConfigurationOptions </em></strong>let&#8217;s you specify SSL property using the property &#8220;Ssl&#8221;. Please set this as true.</li>
</ul>



<p></p>



<ul class="wp-block-list">
<li>PATH_TO_CERT_FILE is the location of the <strong><em>X509Certificate2 </em></strong>certificate file on the server. </li>
</ul>



<p></p>



<p><strong>Example</strong>&#8211;   &#8220;c:\\cert\\path\\CERT.pfx&#8221;;</p>



<p></p>



<p></p>



<p>If using the ASP.NET Core application below is a sample that can be used to specify the certificate file.</p>



<p></p>



<p>If using the cloud with docker, please specify the docker file with the certificate location.</p>



<p></p>



<h2 class="wp-block-heading" id="aioseo-asp-net-core-example-for-redis-ssl"><strong>ASP.NET Core example for Redis SSL </strong></h2>



<p></p>



<pre class="wp-block-syntaxhighlighter-code">public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();
            services.AddScoped&lt;ISalaryRepository, SalaryRepository>();
            services.AddDbContext&lt;EmployeeContext>(options =>
            {
                options.UseSqlServer(Configuration.GetConnectionString("EmployeeDB"),
                sqlServerOptionsAction: sqlOptions =>
                {
                    sqlOptions.EnableRetryOnFailure();
                });
            });
 
            if (_hostEnvironment.IsDevelopment())
            {
                services.AddDistributedMemoryCache();//Use this for only DEV testing purpose
            }
            else
            {
               var configurationOptions = new ConfigurationOptions
                {
                    EndPoints = { $"{Configuration.GetValue&lt;string>("RedisCache:Host")}:{Configuration.GetValue&lt;int>("RedisCache:Port")}" },
                    Ssl = true,
                };
                configurationOptions.CertificateSelection += delegate
                {
                    var cert = new X509Certificate2(Configuration.GetValue&lt;string>("RedisCache:CertificatePath"), "");
                    return cert;
                };
                var multiplexer = ConnectionMultiplexer.Connect(configurationOptions); ;
                
                services.AddSingleton&lt;IConnectionMultiplexer>(multiplexer);
            }
</pre>



<p> </p>



<p>In a case using a self-signed certificate, then please make sure to install the certificate on your server.</p>



<p></p>



<p><strong><em>References</em></strong>: </p>



<p></p>



<ul class="wp-block-list">
<li><a href="https://www.thecodebuzz.com/redis-distributed-cache-asp-net-core-csharp-redis-examples/" title="Redis Distributed cache in .NET with examples" target="_blank" rel="noreferrer noopener"><strong><em>Redis Distributed cache in .NET with examples</em></strong></a></li>
</ul>



<p></p>



<p style="font-size:18px">Do you have any <strong>comments or ideas or any better </strong>suggestions to share?</p>



<p class="has-small-font-size"></p>



<p style="font-size:18px">Please sound off your comments below.</p>



<p class="has-medium-font-size"></p>



<p class="has-medium-font-size"><strong>Happy Coding </strong>!!</p>



<p></p>



<hr>



<p class=""></p>



<p class="has-background" style="background-color:#b6d9ac;font-size:18px"><br>Please <strong><em>bookmark </em></strong>this page and <em><strong>share </strong></em>it with your friends.                                                    Please <a href="https://www.thecodebuzz.com/subscription/" target="_blank" rel="noreferrer noopener"><em><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color"><strong>Subscribe</strong> </mark></em></a>to the blog to receive notifications on freshly published (2025) best practices and guidelines for software design and development.</p>




<br>



<hr>



<p class=""></p>



<p></p>



<p></p><p>The post <a href="https://thecodebuzz.com/redis-connect-with-ssl-tls-using-csharp-asp-net-core/">Redis Connect with SSL/TLS using C# .NET</a> first appeared on <a href="https://thecodebuzz.com">TheCodeBuzz</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://thecodebuzz.com/redis-connect-with-ssl-tls-using-csharp-asp-net-core/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>Publish and Subscribe messages with Redis &#8211; C# .NET Core</title>
		<link>https://thecodebuzz.com/redis-publish-subscribe-messages-redis-net-core-csharp/</link>
					<comments>https://thecodebuzz.com/redis-publish-subscribe-messages-redis-net-core-csharp/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Sun, 19 Sep 2021 22:34:00 +0000</pubDate>
				<category><![CDATA[Redis]]></category>
		<category><![CDATA[c# redis set]]></category>
		<category><![CDATA[pub sub redis]]></category>
		<category><![CDATA[pub/sub in .net core]]></category>
		<category><![CDATA[Publish Subscribe Redis]]></category>
		<category><![CDATA[Redis .NET]]></category>
		<category><![CDATA[Redis .NET Core]]></category>
		<category><![CDATA[redis pub/sub protocol]]></category>
		<category><![CDATA[redis pub/sub queue]]></category>
		<category><![CDATA[redis queue .net core]]></category>
		<category><![CDATA[redis subscribe to key]]></category>
		<category><![CDATA[stackexchange redis pub/sub]]></category>
		<guid isPermaLink="false">https://www.thecodebuzz.com/?p=18767</guid>

					<description><![CDATA[<p>Publish and Subscribe messages with Redis &#8211; C# .NET Core Today in this article, we shall see how to Publish and Subscribe messages with Redis using C# .NET Core. Redis is widely regarded as the most efficient cache tool for stateless back-end app servers. Many people are however unaware that apart from an excellent cache [&#8230;]</p>
<p>The post <a href="https://thecodebuzz.com/redis-publish-subscribe-messages-redis-net-core-csharp/">Publish and Subscribe messages with Redis – C# .NET Core</a> first appeared on <a href="https://thecodebuzz.com">TheCodeBuzz</a>.</p>]]></description>
										<content:encoded><![CDATA[<h1 class="wp-block-heading">Publish and Subscribe messages with Redis &#8211; C# .NET Core</h1>



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="530" src="https://www.thecodebuzz.com/wp-content/uploads/2021/10/redis-publish-subscribe-net-core-c-example-1-1024x530.jpg" alt="Publish and Subscribe messages with Redis" class="wp-image-18801" srcset="https://thecodebuzz.com/wp-content/uploads/2021/10/redis-publish-subscribe-net-core-c-example-1-1024x530.jpg 1024w, https://thecodebuzz.com/wp-content/uploads/2021/10/redis-publish-subscribe-net-core-c-example-1-300x155.jpg 300w, https://thecodebuzz.com/wp-content/uploads/2021/10/redis-publish-subscribe-net-core-c-example-1-768x398.jpg 768w, https://thecodebuzz.com/wp-content/uploads/2021/10/redis-publish-subscribe-net-core-c-example-1-1536x795.jpg 1536w, https://thecodebuzz.com/wp-content/uploads/2021/10/redis-publish-subscribe-net-core-c-example-1-2048x1060.jpg 2048w, https://thecodebuzz.com/wp-content/uploads/2021/10/redis-publish-subscribe-net-core-c-example-1-785x406.jpg 785w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p>Today in this article, we shall see how to Publish and Subscribe messages with Redis using C# .NET Core.</p>



<p></p>



<p> Redis is widely regarded as the most efficient cache tool for stateless back-end app servers. </p>



<p></p>



<p>Many people are however unaware that apart from an excellent cache server, it also provides built-in Publishing / Subscribe / Messaging functionality helping developers create event-driven based applications, microservices, etc. </p>



<p></p>



<p>Today in this article, we will cover below aspects,</p>



<p></p>



<div class="wp-block-aioseo-table-of-contents"><ul><li><a href="#aioseo-getting-started">Getting started</a></li><li><a href="#aioseo-publish-subscribe-messages-with-redis-subscriber-example-c">Publish/Subscribe messages with Redis &#8211; subscriber example C#</a></li><li><a href="#aioseo-publish-subscribe-messages-with-redis-publisher-example-c">Publish/Subscribe messages with Redis &#8211; Publisher example c#</a></li></ul></div>



<p></p>



<p></p>



<p>Today in this article, we shall try to cover the basics pub-sub model and how to get started.</p>



<p></p>



<p></p>



<h2 class="wp-block-heading" id="aioseo-getting-started">Getting started</h2>



<p></p>



<p>Let&#8217;s start creating&nbsp;<strong>.NET Core</strong>&nbsp;console application as below,</p>



<p></p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="182" src="https://www.thecodebuzz.com/wp-content/uploads/2021/10/redis-net-core-csharp-c-console-app-1024x182.jpg" alt="Redis subscriber example C#" class="wp-image-18798" srcset="https://thecodebuzz.com/wp-content/uploads/2021/10/redis-net-core-csharp-c-console-app-1024x182.jpg 1024w, https://thecodebuzz.com/wp-content/uploads/2021/10/redis-net-core-csharp-c-console-app-300x53.jpg 300w, https://thecodebuzz.com/wp-content/uploads/2021/10/redis-net-core-csharp-c-console-app-768x137.jpg 768w, https://thecodebuzz.com/wp-content/uploads/2021/10/redis-net-core-csharp-c-console-app-1536x273.jpg 1536w, https://thecodebuzz.com/wp-content/uploads/2021/10/redis-net-core-csharp-c-console-app-2048x364.jpg 2048w, https://thecodebuzz.com/wp-content/uploads/2021/10/redis-net-core-csharp-c-console-app-785x140.jpg 785w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p></p>



<p id="block-4161c405-d64c-4900-87b3-4bfcf3a14725">Please install the&nbsp;<strong><em>Redis&nbsp;</em></strong>NuGet package&nbsp;<a href="https://www.nuget.org/packages/Microsoft.Extensions.Caching.StackExchangeRedis/5.0.1" target="_blank" rel="noreferrer noopener"><em><strong>Microsoft.Extensions.Caching.StackExchangeRedis</strong></em></a></p>



<p id="block-4161c405-d64c-4900-87b3-4bfcf3a14725">as below,</p>



<p></p>



<pre class="wp-block-preformatted has-medium-font-size"><strong>> Install-Package<a href="https://www.nuget.org/packages/Microsoft.Extensions.Caching.StackExchangeRedis/5.0.1" target="_blank" rel="noreferrer noopener"> Microsoft.Extensions.Caching.StackExchangeRedis</a> -Version </strong>&lt;version></pre>



<p></p>



<h2 class="wp-block-heading" id="aioseo-publish-subscribe-messages-with-redis-subscriber-example-c">Publish/Subscribe messages with Redis &#8211; subscriber example C#</h2>



<p></p>



<p>Below shows a simple example for Redis subscribers.</p>



<p></p>



<pre class="wp-block-syntaxhighlighter-code">            using ConnectionMultiplexer redis = 
            ConnectionMultiplexer.Connect(redisConnectionString);
            ISubscriber subScriber = redis.GetSubscriber();
            //Subscribe to the channel "thecode-buzz-channel"
            subScriber.Subscribe(publishChannel, (channel, message) =>
            {
                //Output received message
                Console.WriteLine($"[{DateTime.Now:HH:mm:ss}]: {$"Message {message} received successfully"}");
            });</pre>



<p></p>



<p>Above we are using the <strong><em>ConnectionMultiplexer interface to create </em></strong>subscriber objects to subscribe to the name channel.</p>



<p></p>



<h2 class="wp-block-heading" id="aioseo-publish-subscribe-messages-with-redis-publisher-example-c">Publish/Subscribe messages with Redis &#8211; Publisher example c#</h2>



<p></p>



<p></p>



<p>Below shows a simple example for Redis  Publisher,</p>



<p></p>



<pre class="wp-block-syntaxhighlighter-code">            using ConnectionMultiplexer redis = 
            ConnectionMultiplexer.Connect(redisConnectionString);
            ISubscriber sub = redis.GetSubscriber();
            for (int i = 0; i &lt;= 10; i++)
            {
                sub.Publish(publishChannel, $"Message {i}");
                Console.WriteLine($"Message {i} published successfully");
                Thread.Sleep(2000);
            }</pre>



<p></p>



<p><strong><em>ConnectionMultiplexer </em>lets you create publisher</strong> objects to create a publisher which can publish the business events to the registered named channel.</p>



<p></p>



<p>For example, we are simply publishing 10 messages to the Redis channel. </p>



<p></p>



<figure class="wp-block-image size-large is-resized"><img loading="lazy" decoding="async" width="320" height="180" src="https://www.thecodebuzz.com/wp-content/uploads/2021/10/gif.gif" alt="Redis Publisher example c#" class="wp-image-18802" style="width:457px;height:257px"/></figure>



<p></p>



<p>All the clients which are subscribed for the updates will receive updates when the message is published to the channel successfully.</p>



<p></p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p><strong><em>ConnectionMultiplexer </em></strong>interface can be used via <em><strong>dependency injection </strong></em>providing better control on lifetime management of the instance. Please visit <em><a href="https://www.thecodebuzz.com/redis-dependency-injection-connectionmultiplexer-redis-cache-netcore-csharp/" target="_blank" rel="noreferrer noopener" title="Redis-Dependency Injection of the ConnectionMultiplexer – Best Practices"><strong>this </strong></a></em>article for more details.</p>
</blockquote>



<p></p>



<p><strong><em>References: </em></strong></p>



<p></p>



<ul class="has-medium-font-size wp-block-list">
<li><a href="https://www.thecodebuzz.com/kafka-asp-net-core-event-driven-microservices/" title="Getting Started with Kafka in ASP.NET Core" target="_blank" rel="noreferrer noopener"><strong><em>Getting Started with Kafka in ASP.NET Core</em></strong></a></li>
</ul>



<ul class="has-medium-font-size wp-block-list">
<li><a href="https://www.thecodebuzz.com/redis-dependency-injection-connectionmultiplexer-redis-cache-netcore-csharp/" target="_blank" rel="noreferrer noopener" title="Redis-Dependency Injection of the ConnectionMultiplexer – Best Practices"><strong><em>Redis-Dependency Injection of the ConnectionMultiplexer</em></strong></a></li>
</ul>



<p></p>



<p>That&#8217;s all! Happy coding!</p>



<p></p>



<p>Does this help you fix your issue? </p>



<p></p>



<p>Do you have any better solutions or suggestions? Please sound off your comments below.</p>



<p></p>



<hr>



<p class=""></p>



<p class="has-background" style="background-color:#b6d9ac;font-size:18px"><br>Please <strong><em>bookmark </em></strong>this page and <em><strong>share </strong></em>it with your friends.                                                    Please <a href="https://www.thecodebuzz.com/subscription/" target="_blank" rel="noreferrer noopener"><em><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color"><strong>Subscribe</strong> </mark></em></a>to the blog to receive notifications on freshly published (2025) best practices and guidelines for software design and development.</p>




<br>



<hr>



<p class=""></p>



<p></p><p>The post <a href="https://thecodebuzz.com/redis-publish-subscribe-messages-redis-net-core-csharp/">Publish and Subscribe messages with Redis – C# .NET Core</a> first appeared on <a href="https://thecodebuzz.com">TheCodeBuzz</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://thecodebuzz.com/redis-publish-subscribe-messages-redis-net-core-csharp/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
