diff --git a/CSRedis/Types.cs b/CSRedis/Types.cs index d423696..18b3f63 100644 --- a/CSRedis/Types.cs +++ b/CSRedis/Types.cs @@ -618,7 +618,10 @@ public class RedisSentinelInfo : RedisServerInfo public RedisSentinelInfo(SerializationInfo info, StreamingContext context) : base(info, context) { - SDownTime = info.GetInt64("s-down-time"); + // safety get from SerializationInfo + var s_down_time = GetSerializationItemValue(info, "s-down-time"); + + SDownTime = s_down_time == 0 ? -1 : s_down_time; LastHelloMessage = info.GetInt64("last-hello-message"); VotedLeader = info.GetString("voted-leader"); VotedLeaderEpoch = info.GetInt64("voted-leader-epoch"); @@ -642,6 +645,26 @@ public RedisSentinelInfo(SerializationInfo info, StreamingContext context) /// Get or set the voted-leader epoch /// public long VotedLeaderEpoch { get; set; } + + /// + /// Get a value from an instance of the SerializationInfo + /// + /// + /// + /// + /// + private T GetSerializationItemValue(SerializationInfo info, string key) + { + foreach (SerializationEntry entry in info) + { + if (entry.Name == key) + { + return (T)Convert.ChangeType(entry.Value, typeof(T), System.Globalization.CultureInfo.InvariantCulture); + } + } + + return default(T); + } } ///