Open XuMengEnEli opened 1 year ago
static GetDatabase 就是错误的设计
除了顶层 RedisClient 支持多线程安全
GetDatabase 返回的虽然是 RedisClient,它但只是一个单一 socket 连接,不支持多线程同时访问的
感谢您的回复,之前不是static的,而是在方法里每次调用时进行切换,但会在运行一段时间后报这个错误(这个链接点进去竟然是FreeSql,哈哈~)
System.TimeoutException: 【redis-dev.default.svc.cluster.local:6379/8】ObjectPool.Get() timeout 10 seconds, see: https://github.com/dotnetcore/FreeSql/discussions/1081
at FreeRedis.Internal.ObjectPool.ObjectPool1.Get(Nullable
1 timeout)
at FreeRedis.RedisClient.PoolingAdapter.GetRedisSocket(CommandPacket cmd)
at FreeRedis.RedisClient.GetDatabase(Nullable1 index) at SJZY.Expand.ABP.Core.Language.LanguageHelper.GetLanguageHashValues(Type tType, String language) at SJZY.Expand.ABP.Core.Language.LanguageHelper.LanguageConversion[T](List
1 data)
at SJZY.CAMS.WorkOrder.Sea.Application.Services.Fcl.WorkOrder.WorkOrderSeaFclService.GetSeaFclInOutPageListAsync(GetWorkOrderSeaFclPageInputDto input) in /var/lib/jenkins/workspace/camsapi-dev/src/WorkOrder/Sea/SJZY.CAMS.WorkOrder.Sea.Application/Services/Fcl/WorkOrder/WorkOrderSeaFclService.cs:line 323
at lambda_method2953(Closure, Object)
at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(ActionContext actionContext, IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.
因为你每次 GetDatabase,并且不 Dispose 归还资源,把 pool 用完了
非常感谢您的指点,我这样做是不是就可以了
using { }
否则,你的循环很大的情况下,不会马上 dispose,语法糖有毒的。
没有GetDatabase时一切功能正常,当使用了这个方法后会时不时的报这个异常
异常信息: System.Net.ProtocolViolationException: Expecting fail MessageType '56,36,52,13,10,49,49,52,48,13,10,36,49,50,13,10,229,161,158,230,181,166,232,183,175,230,150,175,13,10,36,52,13,10,49,50,51,57,13,10,36,49,53,13,10,230,178,153,231,137,185,233,152,191,230,139,137,228,188,175,13,10,36,52,13,10,49,49,48,49,13,10,36,57,13,10,229,174,137,233,129,147,229,176,148,13,10,36,52,13,10,49,49,48,50,13,10,36,57,13,10,233,152,191,232,129,148,233,133,139,13,10' at FreeRedis.RespHelper.Resp3Reader.ReadObject(Encoding encoding) at FreeRedis.Internal.DefaultRedisSocket.Read(CommandPacket cmd) at FreeRedis.Internal.DefaultRedisSocket.TempProxyRedisSocket.Read(CommandPacket cmd) at FreeRedis.RedisClient.SingleTempAdapter.<>cDisplayClass6_0g Logged|12_1(ControllerActionInvoker invoker)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.gAwaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g Awaited|26_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
1.<AdapterCall>b__0() at FreeRedis.RedisClient.LogCallCtrl[T](CommandPacket cmd, Func
1 func, Boolean aopBefore, Boolean aopAfter) at FreeRedis.RedisClient.LogCall[T](CommandPacket cmd, Func1 func) at FreeRedis.RedisClient.SingleTempAdapter.AdapterCall[TValue](CommandPacket cmd, Func
2 parse) at FreeRedis.RedisClient.Call[TValue](CommandPacket cmd, Func2 parse) at FreeRedis.RedisClient.HGetAll(String key) at SJZY.Expand.ABP.Core.Language.LanguageHelper.GetLanguageHashValues(Type tType, String language) at SJZY.Expand.ABP.Core.Language.LanguageHelper.LanguageConversion[T](UnifyPageResultDto
1 data) at SJZY.MasterData.Application.Services.GeographicalBase.CityService.GetPage(GetCityPageInput input) in /var/lib/jenkins/workspace/masterdataapi-test/src/SJZY.MasterData.Application/Services/GeographicalBase/CityService.cs:line 54 at lambda_method2182(Closure, Object) at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(ActionContext actionContext, IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.使用场景
封装的helper类