pauliusnrk
pauliusnrk

Reputation: 593

Whats the correct way to maintain ConnectionMultiplexer object in StackExchange.Redis?

I'm are storing ConnectionMultiplexer static object in ASP.NET MVC website getting ~500req/sec which are hitting Redis instance on RedisLabs. Once in a while I see errors saying SocketFailure on EVAL and increased connection count on RedisLabs dashboard. Should I have dispose old ConnectionMultiplexer instance and recreate new or try reconnect manually after those exceptions?

Upvotes: 3

Views: 3649

Answers (1)

Marc Gravell
Marc Gravell

Reputation: 1062650

The system should attempt to reconnect automatically. What it does not do is retry your commands, because it has no way of knowing what did and did not complete at the server (because: the socket failed; for all it knows, the "ok" response could have already been sent by redis).

So, you should not need to dispose/reconnect. You can monitor the connection failure/reconnect via events published on the multiplexer instance. You can also use the .IsConnected() method on a database (this takes a key for server targeting reasons, but if you are only talking to one server, you could pass anything as the key).

Upvotes: 2

Related Questions