2881099 / FreeRedis

🦄 FreeRedis is .NET40+ redis client. supports cluster, sentinel, master-slave, pub-sub, lua, pipeline, transaction, streams, client-side-caching, and pooling.
MIT License
920 stars 164 forks source link

切库时偶发问题 #162

Open XuMengEnEli opened 1 year ago

XuMengEnEli commented 1 year ago

没有GetDatabase时一切功能正常,当使用了这个方法后会时不时的报这个异常

2881099 commented 1 year ago

static GetDatabase 就是错误的设计

除了顶层 RedisClient 支持多线程安全

2881099 commented 1 year ago

GetDatabase 返回的虽然是 RedisClient,它但只是一个单一 socket 连接,不支持多线程同时访问的

XuMengEnEli commented 1 year ago

感谢您的回复,之前不是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(Nullable1 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](List1 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.gLogged|12_1(ControllerActionInvoker invoker) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.g__Awaited|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.gAwaited|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)

2881099 commented 1 year ago

因为你每次 GetDatabase,并且不 Dispose 归还资源,把 pool 用完了

XuMengEnEli commented 1 year ago

非常感谢您的指点,我这样做是不是就可以了 image

2881099 commented 1 year ago

using { }

否则,你的循环很大的情况下,不会马上 dispose,语法糖有毒的。