In my caching AddItem
and GetItem
methods, I check if the connection to redis is alive or not before proceeding, is ConnectionMultiplexer.IsConnected
an expensive method call? or should I just catch an exception and reconnect in that case?
Looking at ConnectionMultiplexer.IsConnected code:
public bool IsConnected
{
get
{
var tmp = serverSnapshot;
for (int i = 0; i < tmp.Length; i++)
if (tmp[i].IsConnected) return true;
return false;
}
}
It seems like all work done here is going through server endpoints to see whether there is at-least one server endpoint connected.
Looking at ServerEndPoint.IsConnected code:
public bool IsConnected
{
get
{
var tmp = interactive;
return tmp != null && tmp.IsConnected;
}
}
All work done here is returning interactive(of type PhysicalBridge) IsConnected value.
Looking at PhysicalBridge.IsConnected code:
public bool IsConnected => state == (int)State.ConnectedEstablished;
You can see all work done here is return whether two int's are equal.
So it seems like very little work is done calling ConnectionMultiplexer.IsConnected property.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With