Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion CSRedis/Types.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Int64>(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");
Expand All @@ -642,6 +645,26 @@ public RedisSentinelInfo(SerializationInfo info, StreamingContext context)
/// Get or set the voted-leader epoch
/// </summary>
public long VotedLeaderEpoch { get; set; }

/// <summary>
/// Get a value from an instance of the SerializationInfo
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="info"></param>
/// <param name="key"></param>
/// <returns></returns>
private T GetSerializationItemValue<T>(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);
}
}

/// <summary>
Expand Down