StackExchange.Redis
StackExchange.Redis copied to clipboard
suber is freeze.
pub:
using System;
using StackExchange.Redis;
class Publisher
{
static void Main()
{
ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("172.16.1.50");
ISubscriber pub = redis.GetSubscriber();
while (true)
{
pub.Publish(RedisChannel.Literal("channel1"), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
}
}
}
sub:
using System;
using System.Threading;
using System.Threading.Tasks;
using StackExchange.Redis;
class Subscriber
{
static int id = 0;
//[System.Runtime.CompilerServices.MethodImpl(MethodImplOptions.NoOptimization)]
static void Main()
{
ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("172.16.1.50");
ISubscriber sub = redis.GetSubscriber();
Task.Run(async () => await sub.SubscribeAsync(RedisChannel.Literal("channel1"), HandleMessage));
while (true)
{
Thread.Sleep(1000);
}
}
static void HandleMessage(RedisChannel channel, RedisValue message)
{
Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + $" id:{id++} Received from {channel}: {message}");
}
}
run in debug mode ,all fine! but run in release mode, after a while,the sub program is freeze. I add [System.Runtime.CompilerServices.MethodImpl(MethodImplOptions.NoOptimization)] to Main(),run fine. I dont know why... I need help,thx!
Are you running the latest version 2.8.24 of StackExchange.Redis? Recent versions contain improvements for subscription connection resilience.
yes ,use the latest version.
I'd advise taking a memory dump here to see what's happening, the best way to investigate what the freeze is would be to inspect the dump (Visual Studio is good for this, as I see in your screenshot used) and use the Debug > Windows > Threads view to see what they're stalled on.