I am trying to write records from a dictionary with around 5000 records to a Redis cache. 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; 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
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 . It has code examples.
And since it seems you don't care about the response, consider flags: CommandFlags.FireAndForget
. See Pipelines and Multiplexers .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.