简体   繁体   English

为什么错误 No connection is available to service this operation: SETEX while write to Redis Cache in C# console application 以及如何解决它

[英]Why error No connection is available to service this operation: SETEX while writing to Redis Cache in C# console application and how to solve it

I am trying to write records from a dictionary with around 5000 records to a Redis cache.我正在尝试将包含大约 5000 条记录的字典中的记录写入 Redis 缓存。 But sometimes I get the below exception, I have no clue why I am getting this error, I have checked on the internet but could not find any solution or root cause of this issue.但有时我会收到以下异常,我不知道为什么会出现此错误,我已经在互联网上进行了检查,但找不到此问题的任何解决方案或根本原因。

using (ConnectionMultiplexer redis = ConnectionMultiplexer.Connect(_configuration.GetConnectionString("redis_server")))
            {
                IDatabase db = redis.GetDatabase();


                foreach (KeyValuePair<string, string> keyValuePair in _dictAllData)
                {
                    db.StringSet(keyValuePair.Key, keyValuePair.Value, TimeSpan.FromMinutes(30));
                }

        }

Exception例外

No connection is available to service this operation: SETEX 747712;没有连接可用于服务此操作:SETEX 747712; IOCP: (Busy=0,Free=1000,Min=4,Max=1000), WORKER: (Busy=0,Free=32767,Min=4,Max=32767), Local-CPU: n/a IOCP: (Busy=0,Free=1000,Min=4,Max=1000), WORKER: (Busy=0,Free=32767,Min=4,Max=32767), Local-CPU: n/a

Edit:编辑:

StackExchange.Redis version: 2.0.601 StackExchange.Redis 版本:2.0.601

Seems like you are running out of connections in the pool (client-side).似乎您的池中的连接用完了(客户端)。 Besides, performance-wise, one set at a time is bad in this case.此外,在性能方面,在这种情况下一次一组是不好的。

You should be using batching or pipelining.您应该使用批处理或流水线。 See Pipelining vs Batching in Stackexchange.Redis .请参阅Stackexchange.Redis 中的流水线与批处理 It has code examples.它有代码示例。

And since it seems you don't care about the response, consider flags: CommandFlags.FireAndForget .由于您似乎并不关心响应,请考虑使用flags: CommandFlags.FireAndForget See Pipelines and Multiplexers .请参阅管道和多路复用器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法在 .net C# 中连接 AWS Redis 缓存 - RedisConnectionException: &#39;没有连接处于活动状态/可用于服务此操作 - Unable to connect AWS Redis cache in .net C# - RedisConnectionException: 'No connection is active/available to service this operation 没有连接可用于服务此操作:使用 Azure Redis 缓存时 - No connection is available to service this operation: when using Azure Redis Cache 没有可用的连接服务此操作:ZRANGEBYSCORE redis - No connection is available to service this operation: ZRANGEBYSCORE redis 没有可用于服务此操作的连接 - Redis with StackExchange.Redis - No connection is available to service this operation - Redis with StackExchange.Redis StackExchange.Redis:没有连接可用于服务此操作:SET - StackExchange.Redis: No connection is available to service this operation: SET 使用Firebird嵌入式数据库时,如何解决C#中的连接错误? - How to solve connection error in c# while using firebird embeded database? C#控制台应用程序无效的操作异常 - C# console application Invalid Operation Exception 退出控制台应用程序C#并写入日志 - exiting console application c# and writing to log C#控制台应用程序未写入桌面 - C# Console Application Not Writing to Desktop 在控制台应用程序中创建HTTPWebRequest时出现Wierd C#错误 - Wierd C# Error while creating a HTTPWebRequest in a Console Application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM