如何解决如何在 ASP .Net Core 中支持 Redis Sentinel
我需要支持 Redis 哨兵以获得高可用性。我创建了一个简单的 .NET Core 控制台应用程序来轻松测试 Redis 哨兵。我通过 ConnectionMultiplexer
of StackExchange.Redis
我在控制台端做的是
var conn = ConnectionMultiplexer.Connect("127.0.0.1:26379," +
"serviceName=mymaster," +
"allowAdmin=true," +
"tiebreaker=\"\"," +
"abortConnect=false");
IDatabase db = conn.GetDatabase();
...
连接后,我试图杀死主服务器,然后 StackExchange 正确地移动到从服务器并使其成为主服务器,一切都很好。
但问题是当我通过 ASP .Net Core Application 应用相同的场景时,手动杀死 master 后,我无法发送与 Redis 相关的请求。
这是我在 Startup.cs
中所做的
var connectionMultiplexer = ConnectionMultiplexer.Connect($"127.0.0.1:26379," +
"serviceName=mymaster," +
"allowAdmin=true," +
"tiebreaker=\"\"," +
"abortConnect=false");
var database = connectionMultiplexer.GetDatabase(0);
services.AddScoped(_ => database);
services.AddMvc(options =>
{
options.EnableEndpointRouting = false;
});
在杀死 master 之后,然后尝试发送一些有关 Redis 的请求,我收到以下错误。
StackExchange.Redis.RedisConnectionException: No connection is available to service this operation: SADD 100001; An existing connection was forcibly closed by the remote host.; IOCP: (Busy=0,Free=1000,Min=16,Max=1000),WORKER: (Busy=2,Free=32765,Max=32767),Local-cpu: n/a
---> StackExchange.Redis.RedisConnectionException: SocketFailure (ReadSocketError/ConnectionReset,last-recv: 20) on 127.0.0.1:6379/Subscription,Idle/Faulted,last: PING,origin: ReadFromPipe,outstanding: 0,last-read: 13s ago,last-write: 13s ago,keep-alive: 60s,state: ConnectedEstablished,mgr: 8 of 10 available,in: 0,in-pipe: 0,out-pipe: 0,last-heartbeat: 0s ago,last-mbeat: 0s ago,global: 0s ago,v: 2.0.593.37019
---> Pipelines.sockets.Unofficial.ConnectionResetException: An existing connection was forcibly closed by the remote host.
---> System.Net.sockets.socketException (10054): An existing connection was forcibly closed by the remote host.
at Pipelines.sockets.Unofficial.Internal.Throw.socket(Int32 errorCode) in C:\code\Pipelines.sockets.Unofficial\src\Pipelines.sockets.Unofficial\Internal\Throw.cs:line 59
at Pipelines.sockets.Unofficial.socketAwaitableEventArgs.GetResult() in C:\code\Pipelines.sockets.Unofficial\src\Pipelines.sockets.Unofficial\SocketAwaitableEventArgs.cs:line 74
at Pipelines.sockets.Unofficial.socketConnection.DoReceiveAsync() in C:\code\Pipelines.sockets.Unofficial\src\Pipelines.sockets.Unofficial\SocketConnection.Receive.cs:line 64
我期待的是在杀死主人后,它应该成功地成为主人,所以我不会出错。
有什么想法吗?我可能缺少什么?谢谢
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。