首页 > 解决方案 > 如何解决 ASP.NET Core 中的 Redis Multiplexer 问题

问题描述

我的 dotnet 核心项目正在使用 redis 进行缓存。在本地工作正常,但我在 ubuntu 服务器中遇到以下错误

错误

StackExchange.Redis.RedisConnectionException: It was not possible to connect to the redis server(s); to create a disconnected multiplexer, disable AbortOnConnectFail. SocketClosed on PING
   at StackExchange.Redis.ConnectionMultiplexer.ConnectAsync(String configuration, TextWriter log) in c:\code\StackExchange.Redis\StackExchange.Redis\StackExchange\Redis\ConnectionMultiplexer.cs:line 799
   at Microsoft.Extensions.Caching.Redis.RedisCache.ConnectAsync(CancellationToken token)
   at Microsoft.Extensions.Caching.Redis.RedisCache.GetAndRefreshAsync(String key, Boolean getData, CancellationToken token)
   at Microsoft.Extensions.Caching.Redis.RedisCache.RefreshAsync(String key, CancellationToken token)
   at Microsoft.AspNetCore.Session.DistributedSession.CommitAsync(CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)

Unhandled Exception: StackExchange.Redis.RedisConnectionException: It was not possible to connect to the redis server(s); to create a disconnected multiplexer, disable AbortOnConnectFail. SocketClosed on PING
   at StackExchange.Redis.ConnectionMultiplexer.ConnectAsync(String configuration, TextWriter log) in c:\code\StackExchange.Redis\StackExchange.Redis\StackExchange\Redis\ConnectionMultiplexer.cs:line 799
   at Microsoft.Extensions.Caching.Redis.RedisCache.ConnectAsync(CancellationToken token)
   at Microsoft.Extensions.Caching.Redis.RedisCache.SetAsync(String key, Byte[] value, DistributedCacheEntryOptions options, CancellationToken token)
   at otpservice.Helper.HOtp.GenerateOtp(String userid) in D:\SampleHelper\HOtp.cs:line 39
   at otpservice.Controllers.OtpController.Otp(Object userData) in D:\Sample\Controllers\OtpController.cs:line 41
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location where exception was thrown ---
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
Aborted

Startup.cs 中的 ConfigureService 方法

 services.AddDistributedRedisCache(options =>
  {
     options.InstanceName = "Sample";
     //For the Server i am using IP Instead of localhost
     options.Configuration = "localhost";
  });

在我的代码中缓存期间

 var cache = new RedisCache(new RedisCacheOptions
  {
      //For the Server i am using IP Instead of localhost
      Configuration = "localhost",
  });

如何解决错误。

谢谢...

标签: asp.net-coreredisasp.net-core-webapiasp.net-core-2.1

解决方案


推荐阅读