[英]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.