如何在Blazor WebAssembly应用程序中使用StackExchange.Redis?
我尝试通过以下方式调用Blazor客户端组件中的如何在Blazor WebAssembly应用程序中使用StackExchange.Redis?,blazor,stackexchange.redis,blazor-client-side,blazor-webassembly,Blazor,Stackexchange.redis,Blazor Client Side,Blazor Webassembly,我尝试通过以下方式调用Blazor客户端组件中的ConnectionMultiplexer.ConnectAsync: protected override async Task OnInitializedAsync() { var configuration = new ConfigurationOptions { AbortOnConnectFail = false, ConnectTimeout = 3000, SyncTimeout = 5000,
ConnectionMultiplexer.ConnectAsync
:
protected override async Task OnInitializedAsync()
{
var configuration = new ConfigurationOptions
{
AbortOnConnectFail = false,
ConnectTimeout = 3000,
SyncTimeout = 5000,
KeepAlive = 180,
EndPoints =
{
{
"localhost", 6379
}
}
};
await ConnectionMultiplexer.ConnectAsync(configuration);
await base.OnInitializedAsync();
}
这会引发一个异常:
无法对儿童进行评估
如何在Blazor WebAssembly
应用程序中使用StackExchange.Redis
编辑:
我在VS输出中发现了更详细的错误消息:
System.NotSupportedException:无法在此运行时上启动线程。
at(包装器管理为本机)System.Threading.Thread.Thread_internal(System.Threading.Thread,System.MulticastDelegate)
位于:0中的System.Threading.Thread.StartInternal(System.Object主体、System.Threading.StackScrawlMark和stackMark)
在System.Threading.Thread.Start(System.Threading.StackScrawlMark和stackMark)处输入:0
在0中的System.Threading.Thread.Start(System.Object参数)处
在C:\Code\Pipelines.Sockets.nonofficial\src\Pipelines.Sockets.nonofficial\indivatedThreadPoolPipeScheduler.StartWorker(System.Int32 id)[0x0003a]中的Pipelines.Sockets.nonofficial\indivatedThreadPoolPipeScheduler.cs:112
在C:\Code\Pipelines.Sockets.non-official\src\Pipelines.Sockets.nonofficial\Sockets.nonofficial\Pipelines.Sockets中的Pipelines.Sockets.indivatedThreadPoolPipeScheduler..ctor(System.String名称、System.Int32 workerCount、System.Int32 useThreadPoolQueueLength、System.Thread.ThreadPriority优先级)[0x00072]处
在//src/StackExchange.Redis/SocketManager.cs:98中的StackExchange.Redis.SocketManager..ctor(System.String名称、System.Int32 workerCount、StackExchange.Redis.SocketManager+SocketManager选项)[0x0006e]处
在//src/StackExchange.Redis/SocketManager.cs:44中的StackExchange.Redis.SocketManager..ctor(System.String名称、System.Int32 workerCount、System.Boolean useHighPrioritySocketThreads)[0x00000]处
在//src/StackExchange.Redis/SocketManager.cs:132中的StackExchange.Redis.SocketManager.get_Shared()[0x0000c]处
在//src/StackExchange.Redis/ConnectionMultiplexer.ReaderWriter.cs:9中的StackExchange.Redis.ConnectionMultiplexer.OnCreateReaderWriter(StackExchange.Redis.ConfigurationOptions配置)[0x00000]处
在//src/StackExchange.Redis/ConnectionMultiplexer.cs:1150中的StackExchange.Redis.ConnectionMultiplexer..ctor(StackExchange.Redis.ConfigurationOptions配置)[0x000d6]处
在StackExchange.Redis.ConnectionMultiplexer.CreateMultiplexer(System.Object配置,StackExchange.Redis.ConnectionMultiplexer+LogProxy日志,System.EventHandler`1[StackExchange.Redis.ConnectionFailedEventArgs]&connectHandler)[0x0000d]中//src/StackExchange.Redis/ConnectionMultiplexer.cs:957
在//uu/src/StackExchange.Redis/ConnectionMultiplexer.cs:854中的StackExchange.Redis.ConnectionMultiplexer.connectionmplasync(System.Object配置,System.IO.TextWriter日志)[0x0003a]
在C:\Users\tomas.fabian\source\repos\Joker.BlazorApp.Sample\Pages.ProductsComponentBase.OnInitializedAsync()[0x0007c]中的Joker.BlazorApp.Sample\Joker.BlazorApp.Sample\BlazorApp.Sample\Pages\ProductsComponentBase.cs:52
位于:0中的Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()处
您不能在blazor webassembly中使用StackExchange Redis,因为它类似于连接和管理Redis的SDK,而不是Redis本身 错误消息是 未处理的异常呈现组件:无法在此运行时上启动线程 意味着它无法在webassembly中运行redis 如果要使用StackExchangeRedis,需要创建一些将与Redis连接的api
如果要在客户端缓存一些数据,可以使用用户
localStorage
/sessionStorage
或IndexedDB
我想使用StackExchange.Redis进行发布/订阅,主要是ISubscriber
部分。我发现,ConnectionMultiplexer
使用了SocketManager
。也许一个不同的实现可以工作,在我看来这是一个线程问题。例如,这在WebAssemblyTaskFactory().StartNew(()=>{})
中起作用,但在新线程(()=>{}.Start()中不起作用new Thread
引发相同的异常:未处理的异常呈现组件:无法在此运行时启动线程。System.NotSupportedException:无法在此运行时启动线程。@TomasFabian在github上查看此问题:您将看到无法实例化新的线程
。因此您是正确的t、 这是一个线程问题tnx,这也是我发现的。似乎TPL部分在某种程度上是有效的,但直接使用线程池无法安排工作。我尝试了这个,但在netstandard 2.1中不起作用:。我现在很好奇,SignalR client是否在web汇编中工作。它使用web套接字。
Unhandled exception rendering component: Cannot start threads on this runtime.