The Basic Usage documentation for StackExchange.Redis explains that the ConnectionMultiplexer
is long-lived and is expected to be reused.
But what about when the connection to the server is broken? Does ConnectionMultiplexer
automatically reconnect, or is it necessary to write code as in this answer (quoting that answer):
if (RedisConnection == null || !RedisConnection.IsConnected)
{
RedisConnection = ConnectionMultiplexer.Connect(...);
}
RedisCacheDb = RedisConnection.GetDatabase();
Is the above code something good to handle recovery from disconnects, or would it actually result in multiple ConnectionMultiplexer
instances? Along the same lines, how should the IsConnected
property be interpreted?
[Aside: I believe the above code is a pretty bad form of lazy initialization, particularly in multithreaded environments - see Jon Skeet's article on Singletons].
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…