简体   繁体   English

SignalR Redis 背板实现

[英]SignalR Redis backplane implementation

Set up redis backplane per article: https://docs.microsoft.com/en-us/aspnet/core/signalr/redis-backplane?view=aspnetcore-3.1 , how would one view published messages in redis?.每篇文章设置 redis 背板: https ://docs.microsoft.com/en-us/aspnet/core/signalr/redis-backplane?view = aspnetcore-3.1 ,如何在 redis 中查看已发布的消息?。 I want to make sure redis pub/sub is actually being used without deploying it to 2 different nodes.我想确保 redis pub/sub 实际上正在使用,而无需将其部署到 2 个不同的节点。

Configuration:配置:

public void ConfigureServices(IServiceCollection services)
{
    services.AddSignalR().AddStackExchangeRedis("localhost:6379", options => {
        options.Configuration.ChannelPrefix = "MyApp";
    });

I would be able to see in redis-cli when a message is sent via (Hub => chat hub):当通过(集线器 => 聊天中心)发送消息时,我将能够在 redis-cli 中看到:

await Clients.All.SendAsync("broadcastMessage", name, message);

It doesn't show anything when subscribed:订阅时它不显示任何内容: 在此处输入图片说明

SUBSCRIBE will subscribe to the exact key that you give it, in this case "MyApp". SUBSCRIBE将订阅您提供的确切密钥,在本例中为“MyApp”。 That is the wrong name though as SignalR will use multiple channels to send messages and will just use "MyApp" as the prefix to the channel names.这是错误的名称,因为 SignalR 将使用多个通道来发送消息,并且只会使用“MyApp”作为通道名称的前缀。

If you want to listen to all channels with "MyApp" at the beginning then you need to use PSUBSCRIBE and give it a pattern for the channel names (like "MyApp*").如果您想收听开头带有“MyApp”的所有频道,则需要使用PSUBSCRIBE并为其指定频道名称模式(例如“MyApp*”)。

Or you can use the MONITOR command to view all the traffic over Redis.或者您可以使用MONITOR命令查看通过 Redis 的所有流量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM