首页 新闻 赞助 找找看

redis 连接超时问题

0
悬赏园豆:50 [已解决问题] 解决于 2022-09-27 10:25

项目中使用到redis 做完缓存,
dll 用的是ServiceStack.Redis
版本:
<PackageReference Include="ServiceStack.Redis" Version="5.10.2" />
<PackageReference Include="StackExchange.Redis" Version="2.2.4" />

redis连接帮助类是RedisBase
private static string[] ReadWriteHosts = { ConfigRead.GetInstance.GetAppsetConnection().RedisIp };
private static string[] ReadOnlyHosts = { ConfigRead.GetInstance.GetAppsetConnection().RedisIp };

    #region -- 连接信息 --
    public static PooledRedisClientManager Prcm = CreateManager(ReadWriteHosts, ReadOnlyHosts);

    private static PooledRedisClientManager CreateManager(string[] readWriteHosts, string[] readOnlyHosts)
    {
        // 支持读写分离,均衡负载  
        return new PooledRedisClientManager(readWriteHosts, readOnlyHosts, new RedisClientManagerConfig
        {
            MaxWritePoolSize = 10000, // “写”链接池链接数  
            MaxReadPoolSize = 10000, // “读”链接池链接数  
            DefaultDb = ConfigRead.GetInstance.GetAppsetConnection().RedisDb,
            AutoStart = true,
        });
    }

异常信息:

MethodName:OnException [(null)]
ServiceStack.Redis.RedisException: Exceeded timeout of 00:00:10
---> System.Net.Sockets.SocketException (10060): 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
--- End of inner exception stack trace ---
at ServiceStack.Redis.RedisNativeClient.SendReceive[T](Byte[][] cmdWithBinaryArgs, Func1 fn, Action1 completePipelineFn, Boolean sendWithoutRead) in C:\BuildAgent\work\b2a0bfe2b1c9a118\src\ServiceStack.Redis\RedisNativeClient_Utils.cs:line 722
at ServiceStack.Redis.RedisNativeClient.SendExpectData(Byte[][] cmdWithBinaryArgs) in C:\BuildAgent\work\b2a0bfe2b1c9a118\src\ServiceStack.Redis\RedisNativeClient_Utils.cs:line 782
at ServiceStack.Redis.RedisClient.<>c__DisplayClass452_01.<Get>b__0(RedisClient r) in C:\BuildAgent\work\b2a0bfe2b1c9a118\src\ServiceStack.Redis\RedisClient.ICacheClient.cs:line 49 at ServiceStack.Redis.RedisClient.Exec[T](Func2 action) in C:\BuildAgent\work\b2a0bfe2b1c9a118\src\ServiceStack.Redis\RedisClient.ICacheClient.cs:line 31
at Hh.Mes.Common.Redis.RedisBase.GetT[T](String key) in D:\工程项目\开发中项目\中海油\TJZHY_MES\Hh.Mes.Common\Redis\RedisBase.cs:line 519
at Hh.Mes.API.AOP.AuthFilterAttribute.OnActionExecuting(ActionExecutingContext context) in D:\工程项目\开发中项目\中海油\TJZHY_MES\Hh.Mes.API\AOP\AuthFilterAttribute.cs:line 92
at Microsoft.AspNetCore.Mvc.Filters.ActionFilterAttribute.OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>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.InvokeInnerFilterAsync()
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextExceptionFilterAsync>g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)

日志里面打印这个错误还是挺频繁的, 访问量也不大 不多,
请问朋友们 你们是怎么解决呢?

s_p的主页 s_p | 初学一级 | 园豆:138
提问于:2022-05-27 10:25
< >
分享
最佳答案
0

建议检查一下 redis 服务器

收获园豆:50
dudu | 高人七级 |园豆:31326 | 2022-05-28 12:43

换成freeRedis 组件 解决了,这个错误网上也看到很多人提出

s_p | 园豆:138 (初学一级) | 2022-09-27 10:27
其他回答(2)
0

把线程最小并发设大点,比如:ThreadPool.SetMinThreads(1000, 1000);

穷其一生 | 园豆:202 (菜鸟二级) | 2022-05-27 15:49
0

查看一下redis 版本~最新的servicestack 是需要高版本的redis来支持的,底层的API不一样。

!!!!!!!!!!!!!!! | 园豆:258 (菜鸟二级) | 2022-05-31 16:30

换成freeRedis 组件 解决了,这个错误网上也看到很多人提出

支持(0) 反对(0) s_p | 园豆:138 (初学一级) | 2022-09-27 10:27
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册