我有一个使用多个 ISubscribers
到 Redis
当其中一个使用 ISubscribers.UnsubscribeAsync/Unsubscribe/UnsubscribeAll/UnsubscribeAllAsync
所有其他的回调都不再触发。
有人知道为什么会这样吗?为了看它是不是从 Redis
,我正在使用 Redis-Cli
作为目标频道的订户 Redis-Cli
作为目标频道的发布者。
在我的代码中,我启动订户,在某个时候我使用 Unsubscribe
在此目标订户取消订阅后,所有其他回调将停止触发:
从左到右:
redis cli订阅服务器
控制台应用程序输出
redis cli发布服务器
如何繁殖
- subscribe K ISubscribers to channel
- publish to channel and all ISubscribers callbacks trigger
- ISubscriber T unsubscribes from channel
- remaining ISubscribers stop having their callbacks called
代码
class Program {
public static string CHANNEL = "chan";
public static TaskCompletionSource<bool> tcs = new System.Threading.Tasks.TaskCompletionSource<bool>();
public static TaskCompletionSource<bool> tcs2 = new TaskCompletionSource<bool>();
public static int INITIAL_COUNT = 3;
static async Task Main(string[] args) {
List<ISubscriber> subs = new List<ISubscriber>();
ConnectionMultiplexer mux = ConnectionMultiplexer.Connect("localhost:6379");
for (int i = 0; i < INITIAL_COUNT; i++) {
var sub = mux.GetSubscriber();
int closuredIdentity = i;
await sub.SubscribeAsync(CHANNEL, async (chan, msg) => {
if(msg=="k" && closuredIdentity == 0) {
Console.WriteLine($"Subscriber[{closuredIdentity}] unsubscribes");
await sub.UnsubscribeAsync(CHANNEL);
tcs.SetResult(true);
}
Console.WriteLine($"From sub[{closuredIdentity}]:{msg}");
});
subs.Add(sub);
}
var destroyerSubscriber = subs.FirstOrDefault();
await tcs.Task;
Console.WriteLine("Messages post unsubscribe");
await destroyerSubscriber.SubscribeAsync(CHANNEL, async (chan, msg) => {
if (msg == "k") {
tcs2.SetResult(true);
}
});
await tcs2.Task;
Console.WriteLine("Hello World!");
}
}
正如你从下面看到的,这似乎是一个 StackExchangeRedis
自从 Redis-Cli
订户即使在 .NET subscriber
取消订阅。所有其他 .NET subscribers
的回调停止触发。
暂无答案!
目前还没有任何答案,快来回答吧!