3

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

Vivek Nuna
  • 25,472
  • 25
  • 109
  • 197

1 Answers1

0

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.

LeoMurillo
  • 6,048
  • 1
  • 19
  • 34
  • 1
    I have tried both solutions, pipelining and batching. both giving the same previous error. – Vivek Nuna Jan 13 '20 at 10:48
  • Try downgrading your StackExchange.Redis version to 2.0.519. There are many reports of this problem with 2.0.571 and later. See https://github.com/StackExchange/StackExchange.Redis/issues/1120 – LeoMurillo Jan 13 '20 at 10:51