无法连接到Redis服务器
本文关键字:Redis 服务器 连接 | 更新日期: 2023-09-27 18:13:42
尝试运行应用程序时出现以下错误:
无法连接到redis服务器;要创建一个断开连接的多路复用器,禁用AbortOnConnectFail。SocketFailure on PING
RedisConnectionException: It was not possible to connect to the redis server(s); to create a disconnected multiplexer, disable AbortOnConnectFail. SocketFailure on PING]
StackExchange.Redis.ConnectionMultiplexer.Connect(ConfigurationOptions configuration, TextWriter log) in c:'TeamCity'buildAgent'work'58bc9a6df18a3782'StackExchange.Redis'StackExchange'Redis'ConnectionMultiplexer.cs:767
Microsoft.Web.Redis.StackExchangeClientConnection..ctor(ProviderConfiguration configuration) +263
Microsoft.Web.Redis.<>c__DisplayClass3.<.ctor>b__1() +26
Microsoft.Web.Redis.RedisSharedConnection.TryGetConnection() +107
Microsoft.Web.Redis.RedisConnectionWrapper..ctor(ProviderConfiguration configuration, String id) +334
Microsoft.Web.Redis.RedisSessionStateProvider.GetItemFromSessionStore(Boolean isWriteLockRequired, HttpContext context, String id, Boolean& locked, TimeSpan& lockAge, Object& lockId, SessionStateActions& actions) +997
Microsoft.Web.Redis.RedisSessionStateProvider.GetItemExclusive(HttpContext context, String id, Boolean& locked, TimeSpan& lockAge, Object& lockId, SessionStateActions& actions) +128
System.Web.SessionState.SessionStateModule.GetSessionStateItem() +111
System.Web.SessionState.SessionStateModule.BeginAcquireState(Object source, EventArgs e, AsyncCallback cb, Object extraData) +778
System.Web.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +254
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
很可能你的连接超时是非常少的,也设置AbortOnConnectFail为false。下面的代码仅供参考,希望对大家有所帮助!
var config = new ConfigurationOptions()
{
KeepAlive = 0,
AllowAdmin = true,
EndPoints = { { "127.0.0.1", 6379 },{ "127.0.0.2", 6379 } },
ConnectTimeout = 5000,
ConnectRetry = 5,
SyncTimeout = 5000,
AbortOnConnectFail = false,
};