{"id":26492,"date":"2020-09-16T00:00:00","date_gmt":"2020-09-15T22:00:00","guid":{"rendered":"https:\/\/blexin.com\/riedisegnamo-il-publish-subscribe-con-redis\/"},"modified":"2021-05-21T20:22:32","modified_gmt":"2021-05-21T18:22:32","slug":"redeisign-publish-subscribe-with-redis","status":"publish","type":"post","link":"https:\/\/blexin.com\/en\/blog-en\/redeisign-publish-subscribe-with-redis\/","title":{"rendered":"\u201cRed(e)isign\u201d Publish\/Subscribe with Redis"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"608\" data-attachment-id=\"26444\" data-permalink=\"https:\/\/blexin.com\/en\/01\/\" data-orig-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/01.png?fit=1024%2C608&amp;ssl=1\" data-orig-size=\"1024,608\" data-comments-opened=\"0\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"01\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/01.png?fit=1024%2C608&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/01.png?resize=1024%2C608&#038;ssl=1\" alt=\"\" class=\"wp-image-26444\" srcset=\"https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/01.png 1024w, https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/01-980x582.png 980w, https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/01-480x285.png 480w\" sizes=\"auto, (min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) and (max-width: 980px) 980px, (min-width: 981px) 1024px, 100vw\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">I recently had the opportunity to work for one of our customers with an application using&nbsp;<a href=\"https:\/\/redis.io\/\" target=\"_blank\" rel=\"noreferrer noopener\">Redis<\/a>. Talking about it with colleagues and studying the documentation, I discovered that this tool could also be used to decouple communication in a software system. Driven by curiosity, I tried to understand better what it was and how I could use it as a&nbsp;<em>messaging system<\/em>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Redis, named after&nbsp;<strong>Re<\/strong>mote&nbsp;<strong>Di<\/strong>ctionary&nbsp;<strong>S<\/strong>erver, is defined as an in-memory data store. It is a key-value store type database, thus the data storage requires a key through which value is identified within the database. In the case of Redis, different types are supported for the values \u200b\u200bassociated with the keys such as strings but also structured data types such as lists and sets.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To experiment with Redis, I used a Docker container created with the following command:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\ndocker run \u2013name redis-pubsub -p 6379:6379 -d redis\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"682\" height=\"278\" data-attachment-id=\"26448\" data-permalink=\"https:\/\/blexin.com\/en\/image0\/\" data-orig-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image0.png?fit=682%2C278&amp;ssl=1\" data-orig-size=\"682,278\" data-comments-opened=\"0\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"image0\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image0.png?fit=682%2C278&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image0.png?resize=682%2C278&#038;ssl=1\" alt=\"\" class=\"wp-image-26448\" srcset=\"https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/image0.png 682w, https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/image0-480x196.png 480w\" sizes=\"auto, (min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) 682px, 100vw\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s see a simple example of how we can save key-value information on Redis using the&nbsp;<a href=\"https:\/\/redis.io\/topics\/rediscli\" target=\"_blank\" rel=\"noreferrer noopener\">redis-cli<\/a>, a potent tool supplied with the product. In particular, the&nbsp;<strong>SET&nbsp;<\/strong>and&nbsp;<strong>GET&nbsp;<\/strong>commands to save and obtain the value saved using the key:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"558\" height=\"112\" data-attachment-id=\"26450\" data-permalink=\"https:\/\/blexin.com\/en\/image1\/\" data-orig-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image1.png?fit=558%2C112&amp;ssl=1\" data-orig-size=\"558,112\" data-comments-opened=\"0\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"image1\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image1.png?fit=558%2C112&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image1.png?resize=558%2C112&#038;ssl=1\" alt=\"\" class=\"wp-image-26450\" srcset=\"https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/image1.png 558w, https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/image1-480x96.png 480w\" sizes=\"auto, (min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) 558px, 100vw\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The most widespread use of Redis is as a database or as a cache, mainly when there is a need to access simple data quickly, thus exploiting the speed of the central memory (however, the possibility of persisting data is still provided).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">From version 2.0, new commands have been introduced for the redis-cli that allow you to create the publish\/subscribe pattern. I have talked extensively about this pattern in previous articles (i.e.,&nbsp;<a href=\"https:\/\/www.blexin.com\/en-US\/Article\/Blog\/Decoupling-the-communication-with-RabbitMQ-40\" target=\"_blank\" rel=\"noreferrer noopener\">this one<\/a>) and then we will focus on how it can be achieved through Redis.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It is expected that a&nbsp;<em>Subscriber&nbsp;<\/em>interested in a specific&nbsp;<em>topic&nbsp;<\/em>can subscribe to the related&nbsp;<em>Channel&nbsp;<\/em>while waiting for a&nbsp;<em>Publisher&nbsp;<\/em>to publish information on that channel. Whether they are publishers or subscribers, clients connect to Redis via TCP connection and communicate with the Redis Server via the&nbsp;<a href=\"https:\/\/redis.io\/topics\/protocol#array-reply\" target=\"_blank\" rel=\"noreferrer noopener\">RESP&nbsp;<\/a>protocol.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Redis uses a&nbsp;<em>hash table<\/em>&nbsp;allocated in memory to keep track of channel names and their subscribers. When a new subscriber wants to subscribe to the channel, the latter is hashed to identify the subscribers\u2019 list, and the new one is added to this. Similarly, in the case of publishing, the list of subscribers of a channel is retrieved and the message will be delivered for each of them.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To show an example of using this Redis feature, I created a simple project in which we have a client (<strong>FeedRssClient<\/strong>), A user can request the subscription to an RSS feed and a&nbsp;<strong>FeedRssPublisher&nbsp;<\/strong>that receives the feed URL from the client elaborates it, and publishes its contents.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To do this I used two application consoles in&nbsp;<em>.NET Core.&nbsp;<\/em>As a Redis client I used the&nbsp;<a href=\"https:\/\/stackexchange.github.io\/StackExchange.Redis\/\" target=\"_blank\" rel=\"noreferrer noopener\">StackExchange.Redis<\/a>&nbsp;library available as a&nbsp;<em>Nuget&nbsp;<\/em>package.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s start with&nbsp;<strong>FeedRssClient:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\nusing StackExchange.Redis;\nusing System;\n \nnamespace FeedRssClient\n{\n    class Program\n    {\n        private const string RedisConnectionString = &quot;localhost&quot;;\n        private static ConnectionMultiplexer connection = ConnectionMultiplexer.Connect(RedisConnectionString);\n        private const string publishChannel = &quot;client-channel&quot;;\n        private const string subscriberChannel = &quot;rss-channel&quot;;\n        private static string feedUrl = string.Empty;\n \n        static void Main()\n        {\n            Console.WriteLine(&quot;FeedRssClient\\r\\n&quot;);\n            Console.WriteLine($&quot;Please enter the RSS feed that you want to follow: &quot;);\n            feedUrl = Console.ReadLine();\n \n            var pubSubConnection = connection.GetSubscriber();\n \n            pubSubConnection.Publish(publishChannel, $&quot;{feedUrl}&quot;);\n            var subscriberChannelMessageQueue = pubSubConnection.Subscribe(subscriberChannel);\n            Console.WriteLine($&quot;List of content: \\r\\n&quot;);\n            subscriberChannelMessageQueue.OnMessage(message =&gt;\n            {\n                Console.WriteLine(message);\n            });\n            Console.ReadLine();\n        }\n    }\n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">First, we establish a connection to the Redis container created previously through the&nbsp;<em>Connect()<\/em>&nbsp;method of the ConnectionMultiplexer. The connection multiplexer is a fundamental element provided by the StackExchange library that allows you to access the Redis database or take advantage of the publish\/subscribe features.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Let\u2019s define two channels: the first one, the&nbsp;<strong>client-channel<\/strong>, will be the channel where the FeedRssClient will publish the address of the RSS feed to which it wants to subscribe; the second one, the&nbsp;<strong>rss-channel<\/strong>, is the channel to which the FeedRssClient will subscribe.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The&nbsp;<em>OnMessage()<\/em>&nbsp;method of the subscription channel ensures that the received messages will be read sequentially.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If there is no need to receive the messages in order, you can also use the concurrent version of this method, which is much more efficient if the messages do not correlate with each other.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s now see the&nbsp;<strong>FeedRssPublisher<\/strong>:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\nusing Microsoft.Toolkit.Parsers.Rss;\nusing StackExchange.Redis;\nusing System;\nusing System.Collections.Generic;\nusing System.Net.Http;\nusing System.Threading.Tasks;\n \nnamespace FeedRssPublisher\n{\n    class Program\n    {\n        private const string RedisConnectionString = &quot;localhost&quot;;\n        private static ConnectionMultiplexer connection = ConnectionMultiplexer.Connect(RedisConnectionString);\n        private const string publishChannel = &quot;rss-channel&quot;;\n        private const string subscriberChannel = &quot;client-channel&quot;;\n \n        static void Main()\n        {\n            Console.WriteLine(&quot;FeedRssPublisher\\r\\n&quot;);\n            var feed = new Feed();\n            var pubSubConnection = connection.GetSubscriber();\n            var feedUrl = string.Empty;\n            var subscriberChannelMessageQueue = pubSubConnection.Subscribe(subscriberChannel);\n \n            subscriberChannelMessageQueue.OnMessage(async message =&gt;\n            {\n                feedUrl = message.ToString().Remove(0, subscriberChannel.Length + 1);\n                var rss = await feed.ParseRSSAsync(feedUrl);\n                Console.WriteLine($&quot;Feed Received: {feedUrl}\\r\\n&quot;);\n                if (rss != null)\n                {\n                    Console.WriteLine(&quot;Start publishing contents ...&quot;);\n                    foreach (var item in rss)\n                    {\n                        pubSubConnection.Publish(publishChannel, $&quot;{item.Title}&quot; + $&quot;\\r\\n{item.Summary}&quot; + $&quot;\\r\\n{item.FeedUrl}\\r\\n&quot;);\n                    }\n                }\n            });\n \n            Console.ReadLine();\n \n        }\n \n        class Feed\n        {\n            public async Task&lt;IEnumerable&lt;RssSchema&gt;&gt; ParseRSSAsync(string feed)\n            {\n                IEnumerable&lt;RssSchema&gt; rss = null;\n \n                using (var client = new HttpClient())\n                {\n                    try\n                    {\n                        feed = await client.GetStringAsync(feed);\n                    }\n                    catch (Exception)\n                    {\n                        throw;\n                    }\n                }\n \n                if (feed != null)\n                {\n                    var parser = new RssParser();\n                    rss = parser.Parse(feed);\n                }\n \n                return rss;\n            }\n        }\n    }\n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">Here too, we create a connection to the Redis container and define the two channels whose roles, in this case, will be inverted compared to the FeedRssClient.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In fact, the FeedRssPublisher will publish the messages on the&nbsp;<strong>rss-channel&nbsp;<\/strong>while it will subscribe to the&nbsp;<strong>client-channel&nbsp;<\/strong>channel.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Immediately after the subscription, the RSS feeds are extracted within the&nbsp;<em>OnMessage()<\/em>&nbsp;method using the Feed class, and subsequently, for each feed, we publish the&nbsp;<em>title<\/em>, the&nbsp;<em>summary,&nbsp;<\/em>and the&nbsp;<em>URL<\/em>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s try the two software with the Rss feed of our blog <a href=\"https:\/\/www.blexin.com\/rssfeed\/articles?lang=en-US\" rel=\"nofollow\">https:\/\/www.blexin.com\/rssfeed\/articles?lang=en-US<\/a>:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"468\" height=\"148\" data-attachment-id=\"26453\" data-permalink=\"https:\/\/blexin.com\/en\/image2\/\" data-orig-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image2.png?fit=468%2C148&amp;ssl=1\" data-orig-size=\"468,148\" data-comments-opened=\"0\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"image2\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image2.png?fit=468%2C148&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image2.png?resize=468%2C148&#038;ssl=1\" alt=\"\" class=\"wp-image-26453\" srcset=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image2.png?w=468&amp;ssl=1 468w, https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image2.png?resize=300%2C95&amp;ssl=1 300w\" sizes=\"auto, (max-width: 468px) 100vw, 468px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The publisher receives the URL of the RSS feed and starts publishing its contents:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"548\" height=\"119\" data-attachment-id=\"26456\" data-permalink=\"https:\/\/blexin.com\/en\/image3\/\" data-orig-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image3.png?fit=548%2C119&amp;ssl=1\" data-orig-size=\"548,119\" data-comments-opened=\"0\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"image3\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image3.png?fit=548%2C119&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image3.png?resize=548%2C119&#038;ssl=1\" alt=\"\" class=\"wp-image-26456\" srcset=\"https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/image3.png 548w, https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/image3-480x104.png 480w\" sizes=\"auto, (min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) 548px, 100vw\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The client receives the list of contents:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1016\" height=\"812\" data-attachment-id=\"26458\" data-permalink=\"https:\/\/blexin.com\/en\/image4\/\" data-orig-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image4.png?fit=1016%2C812&amp;ssl=1\" data-orig-size=\"1016,812\" data-comments-opened=\"0\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"image4\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image4.png?fit=1016%2C812&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image4.png?resize=1016%2C812&#038;ssl=1\" alt=\"\" class=\"wp-image-26458\" srcset=\"https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/image4.png 1016w, https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/image4-980x783.png 980w, https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/image4-480x384.png 480w\" sizes=\"auto, (min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) and (max-width: 980px) 980px, (min-width: 981px) 1016px, 100vw\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Of course, we can also use the redis-cli to subscribe to the&nbsp;<strong>rss-channel<\/strong>:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"888\" height=\"522\" data-attachment-id=\"26460\" data-permalink=\"https:\/\/blexin.com\/en\/image6\/\" data-orig-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image6.png?fit=888%2C522&amp;ssl=1\" data-orig-size=\"888,522\" data-comments-opened=\"0\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"image6\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image6.png?fit=888%2C522&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/image6.png?resize=888%2C522&#038;ssl=1\" alt=\"\" class=\"wp-image-26460\" srcset=\"https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/image6.png 888w, https:\/\/blexin.com\/wp-content\/uploads\/2020\/12\/image6-480x282.png 480w\" sizes=\"auto, (min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) 888px, 100vw\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">As we have seen from the example, it is very simple to create the publish\/subscribe pattern with Redis, and obtain a decoupled software system.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The use of Redis allows us to obtain a lean and efficient messaging system both for the in-memory nature of Redis and for scalability or the ability to configure it in a distributed manner.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, the Pub\/Sub mechanism is widely used in real-time applications. Consider, for example, chat rooms or those application scenarios in which you need to collect a large amount of data (<em>data ingestion<\/em>) and process these large volumes at high speed (<em>stream processing<\/em>). Another interesting example that we will see in a future article is using Redis to scale ASP.NET Core SignalR applications.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">However, it must be considered that this mechanism is of the<em>&nbsp;fire &amp; forget&nbsp;<\/em>type and therefore does not provide any persistence for messages with the consequent impossibility of recovering messages in case of a client disconnection.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I hope this Redis feature just described will be useful and interesting.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I leave you the link of the&nbsp;<a href=\"https:\/\/github.com\/intersect88\/RedisPubSub\" target=\"_blank\" rel=\"noreferrer noopener\">GitHub repository<\/a>&nbsp;where you can find the code used for the example and the references used to create the article:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/redis.io\/topics\/pubsub\">https:\/\/redis.io\/topics\/pubsub<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/making.pusher.com\/redis-pubsub-under-the-hood\">https:\/\/making.pusher.com\/redis-pubsub-under-the-hood<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">See you in the next article!<\/p>\n\n\n\n\n","protected":false},"excerpt":{"rendered":"<p>Redis is not only an excellent key-value store for caching but can also be used as a message broker: let&#8217;s see how!<\/p>\n","protected":false},"author":196716251,"featured_media":26444,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"off","_et_pb_old_content":"","_et_gb_content_width":"","_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","inline_featured_image":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"_wpas_customize_per_network":false,"jetpack_post_was_ever_published":false},"categories":[688637524],"tags":[688637546],"class_list":["post-26492","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog-en","tag-docker-en"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>\u201cRed(e)isign\u201d Publish\/Subscribe with Redis - Blexin<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/blexin.com\/en\/blog-en\/redeisign-publish-subscribe-with-redis\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u201cRed(e)isign\u201d Publish\/Subscribe with Redis - Blexin\" \/>\n<meta property=\"og:description\" content=\"Redis is not only an excellent key-value store for caching but can also be used as a message broker: let&#039;s see how!\" \/>\n<meta property=\"og:url\" content=\"https:\/\/blexin.com\/en\/blog-en\/redeisign-publish-subscribe-with-redis\/\" \/>\n<meta property=\"og:site_name\" content=\"Blexin\" \/>\n<meta property=\"article:published_time\" content=\"2020-09-15T22:00:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-05-21T18:22:32+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/01.png?fit=1024%2C608&ssl=1\" \/>\n\t<meta property=\"og:image:width\" content=\"1024\" \/>\n\t<meta property=\"og:image:height\" content=\"608\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Genny Paudice\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Genny Paudice\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/redeisign-publish-subscribe-with-redis\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/redeisign-publish-subscribe-with-redis\\\/\"},\"author\":{\"name\":\"Genny Paudice\",\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/#\\\/schema\\\/person\\\/ae0e97a3ebb79d2f73e4411c1eb28973\"},\"headline\":\"\u201cRed(e)isign\u201d Publish\\\/Subscribe with Redis\",\"datePublished\":\"2020-09-15T22:00:00+00:00\",\"dateModified\":\"2021-05-21T18:22:32+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/redeisign-publish-subscribe-with-redis\\\/\"},\"wordCount\":1027,\"image\":{\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/redeisign-publish-subscribe-with-redis\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/blexin.com\\\/wp-content\\\/uploads\\\/2020\\\/12\\\/01.png?fit=1024%2C608&ssl=1\",\"keywords\":[\"Docker\"],\"articleSection\":[\"Blog\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/redeisign-publish-subscribe-with-redis\\\/\",\"url\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/redeisign-publish-subscribe-with-redis\\\/\",\"name\":\"\u201cRed(e)isign\u201d Publish\\\/Subscribe with Redis - Blexin\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/redeisign-publish-subscribe-with-redis\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/redeisign-publish-subscribe-with-redis\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/blexin.com\\\/wp-content\\\/uploads\\\/2020\\\/12\\\/01.png?fit=1024%2C608&ssl=1\",\"datePublished\":\"2020-09-15T22:00:00+00:00\",\"dateModified\":\"2021-05-21T18:22:32+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/#\\\/schema\\\/person\\\/ae0e97a3ebb79d2f73e4411c1eb28973\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/redeisign-publish-subscribe-with-redis\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/redeisign-publish-subscribe-with-redis\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/redeisign-publish-subscribe-with-redis\\\/#primaryimage\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/blexin.com\\\/wp-content\\\/uploads\\\/2020\\\/12\\\/01.png?fit=1024%2C608&ssl=1\",\"contentUrl\":\"https:\\\/\\\/i0.wp.com\\\/blexin.com\\\/wp-content\\\/uploads\\\/2020\\\/12\\\/01.png?fit=1024%2C608&ssl=1\",\"width\":1024,\"height\":608},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/blog-en\\\/redeisign-publish-subscribe-with-redis\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/blexin.com\\\/en\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u201cRed(e)isign\u201d Publish\\\/Subscribe with Redis\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/#website\",\"url\":\"https:\\\/\\\/blexin.com\\\/en\\\/\",\"name\":\"Blexin\",\"description\":\"Con noi \u00e8 semplice\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/blexin.com\\\/en\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/blexin.com\\\/en\\\/#\\\/schema\\\/person\\\/ae0e97a3ebb79d2f73e4411c1eb28973\",\"name\":\"Genny Paudice\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3093a6ee7b7f555e94e4a5d6f19cb09f3af33635007643b2076eb89329789828?s=96&d=identicon&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3093a6ee7b7f555e94e4a5d6f19cb09f3af33635007643b2076eb89329789828?s=96&d=identicon&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3093a6ee7b7f555e94e4a5d6f19cb09f3af33635007643b2076eb89329789828?s=96&d=identicon&r=g\",\"caption\":\"Genny Paudice\"},\"url\":\"https:\\\/\\\/blexin.com\\\/en\\\/author\\\/genny-paudiceblexin-com\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u201cRed(e)isign\u201d Publish\/Subscribe with Redis - Blexin","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/blexin.com\/en\/blog-en\/redeisign-publish-subscribe-with-redis\/","og_locale":"en_US","og_type":"article","og_title":"\u201cRed(e)isign\u201d Publish\/Subscribe with Redis - Blexin","og_description":"Redis is not only an excellent key-value store for caching but can also be used as a message broker: let's see how!","og_url":"https:\/\/blexin.com\/en\/blog-en\/redeisign-publish-subscribe-with-redis\/","og_site_name":"Blexin","article_published_time":"2020-09-15T22:00:00+00:00","article_modified_time":"2021-05-21T18:22:32+00:00","og_image":[{"width":1024,"height":608,"url":"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/01.png?fit=1024%2C608&ssl=1","type":"image\/png"}],"author":"Genny Paudice","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Genny Paudice","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/blexin.com\/en\/blog-en\/redeisign-publish-subscribe-with-redis\/#article","isPartOf":{"@id":"https:\/\/blexin.com\/en\/blog-en\/redeisign-publish-subscribe-with-redis\/"},"author":{"name":"Genny Paudice","@id":"https:\/\/blexin.com\/en\/#\/schema\/person\/ae0e97a3ebb79d2f73e4411c1eb28973"},"headline":"\u201cRed(e)isign\u201d Publish\/Subscribe with Redis","datePublished":"2020-09-15T22:00:00+00:00","dateModified":"2021-05-21T18:22:32+00:00","mainEntityOfPage":{"@id":"https:\/\/blexin.com\/en\/blog-en\/redeisign-publish-subscribe-with-redis\/"},"wordCount":1027,"image":{"@id":"https:\/\/blexin.com\/en\/blog-en\/redeisign-publish-subscribe-with-redis\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/01.png?fit=1024%2C608&ssl=1","keywords":["Docker"],"articleSection":["Blog"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/blexin.com\/en\/blog-en\/redeisign-publish-subscribe-with-redis\/","url":"https:\/\/blexin.com\/en\/blog-en\/redeisign-publish-subscribe-with-redis\/","name":"\u201cRed(e)isign\u201d Publish\/Subscribe with Redis - Blexin","isPartOf":{"@id":"https:\/\/blexin.com\/en\/#website"},"primaryImageOfPage":{"@id":"https:\/\/blexin.com\/en\/blog-en\/redeisign-publish-subscribe-with-redis\/#primaryimage"},"image":{"@id":"https:\/\/blexin.com\/en\/blog-en\/redeisign-publish-subscribe-with-redis\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/01.png?fit=1024%2C608&ssl=1","datePublished":"2020-09-15T22:00:00+00:00","dateModified":"2021-05-21T18:22:32+00:00","author":{"@id":"https:\/\/blexin.com\/en\/#\/schema\/person\/ae0e97a3ebb79d2f73e4411c1eb28973"},"breadcrumb":{"@id":"https:\/\/blexin.com\/en\/blog-en\/redeisign-publish-subscribe-with-redis\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/blexin.com\/en\/blog-en\/redeisign-publish-subscribe-with-redis\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/blexin.com\/en\/blog-en\/redeisign-publish-subscribe-with-redis\/#primaryimage","url":"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/01.png?fit=1024%2C608&ssl=1","contentUrl":"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/01.png?fit=1024%2C608&ssl=1","width":1024,"height":608},{"@type":"BreadcrumbList","@id":"https:\/\/blexin.com\/en\/blog-en\/redeisign-publish-subscribe-with-redis\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/blexin.com\/en\/"},{"@type":"ListItem","position":2,"name":"\u201cRed(e)isign\u201d Publish\/Subscribe with Redis"}]},{"@type":"WebSite","@id":"https:\/\/blexin.com\/en\/#website","url":"https:\/\/blexin.com\/en\/","name":"Blexin","description":"Con noi \u00e8 semplice","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/blexin.com\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/blexin.com\/en\/#\/schema\/person\/ae0e97a3ebb79d2f73e4411c1eb28973","name":"Genny Paudice","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/3093a6ee7b7f555e94e4a5d6f19cb09f3af33635007643b2076eb89329789828?s=96&d=identicon&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/3093a6ee7b7f555e94e4a5d6f19cb09f3af33635007643b2076eb89329789828?s=96&d=identicon&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/3093a6ee7b7f555e94e4a5d6f19cb09f3af33635007643b2076eb89329789828?s=96&d=identicon&r=g","caption":"Genny Paudice"},"url":"https:\/\/blexin.com\/en\/author\/genny-paudiceblexin-com\/"}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/blexin.com\/wp-content\/uploads\/2020\/12\/01.png?fit=1024%2C608&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/pcyUBx-6Ti","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/posts\/26492","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/users\/196716251"}],"replies":[{"embeddable":true,"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/comments?post=26492"}],"version-history":[{"count":9,"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/posts\/26492\/revisions"}],"predecessor-version":[{"id":32928,"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/posts\/26492\/revisions\/32928"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/media\/26444"}],"wp:attachment":[{"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/media?parent=26492"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/categories?post=26492"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blexin.com\/en\/wp-json\/wp\/v2\/tags?post=26492"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}