July 07 2025
dotnet new console -n OrderPublisher cd OrderPublisher dotnet add package StackExchange.Redis cd .. dotnet new console -n OrderSubscriber cd OrderSubscriber dotnet add package StackExchange.Redis
docker run -p 6379:6379 redis
using StackExchange.Redis; var redis = await ConnectionMultiplexer.ConnectAsync("localhost:6379"); var pub = redis.GetSubscriber(); Console.WriteLine("Publisher connected to Redis."); Console.WriteLine("Type an order ID to publish (or 'exit' to quit):"); while (true) { var input = Console.ReadLine(); if (input?.ToLower() == "exit") break; await pub.PublishAsync(RedisChannel.Literal("orders.new"), input); Console.WriteLine($"[{DateTime.Now.T}]: Published: {input}"); }
using StackExchange.Redis; var redis = await ConnectionMultiplexer.ConnectAsync("localhost:6379"); var sub = redis.GetSubscriber(); Console.WriteLine("Subscriber connected to Redis."); Console.WriteLine("Listening for new orders on 'orders.new'..."); await sub.SubscribeAsync(RedisChannel.Literal("orders.new"), (channel, message) => { Console.WriteLine($"[{DateTime.Now:T}] New order received: {message}"); }); await Task.Delay(Timeout.Infinite);
await sub.SubscribeAsync("orders.*", (channel, message) => { Console.WriteLine($"Wildcard message on {channel}: {message}"); });
var env = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "dev"; await pub.PublishAsync($"{env}.orders.new", orderId);
var orderJson = JsonSerializer.Serialize(new { OrderId = "123", Total = 99.9 }); await pub.PublishAsync("orders.new", orderJson);
1. Design Patterns that Deliver
This isn’t just another design patterns book. Dive into real-world examples and practical solutions to real problems in real applications.Check out it here.
Go-to resource for understanding the core concepts of design patterns without the overwhelming complexity. In this concise and affordable ebook, I've distilled the essence of design patterns into an easy-to-digest format. It is a Beginner level. Check out it here.
Every Monday morning, I share 1 actionable tip on C#, .NET & Arcitecture topic, that you can use right away.
Join 18,000+ subscribers to improve your .NET Knowledge.
Subscribe to the TheCodeMan.net and be among the 18,000+ subscribers gaining practical tips and resources to enhance your .NET expertise.