Skip to content

Commit

Permalink
Implement KeyValuePairParser.TryRead for Int64 (#1568)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrnola authored Sep 10, 2020
1 parent ad94bd3 commit 8b64a53
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/StackExchange.Redis/ResultProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1550,7 +1550,8 @@ protected override StreamConsumerInfo ParseItem(in RawResult result)

var arr = result.GetItems();
string name = default;
int pendingMessageCount = default, idleTimeInMilliseconds = default;
int pendingMessageCount = default;
long idleTimeInMilliseconds = default;

KeyValuePairParser.TryRead(arr, KeyValuePairParser.Name, ref name);
KeyValuePairParser.TryRead(arr, KeyValuePairParser.Pending, ref pendingMessageCount);
Expand All @@ -1566,20 +1567,30 @@ internal static readonly CommandBytes
Name = "name", Consumers = "consumers", Pending = "pending", Idle = "idle", LastDeliveredId = "last-delivered-id",
IP = "ip", Port = "port";

internal static bool TryRead(Sequence<RawResult> pairs, in CommandBytes key, ref int value)
internal static bool TryRead(Sequence<RawResult> pairs, in CommandBytes key, ref long value)
{
var len = pairs.Length / 2;
for (int i = 0; i < len; i++)
{
if (pairs[i * 2].IsEqual(key) && pairs[(i * 2) + 1].TryGetInt64(out var tmp))
{
value = checked((int)tmp);
value = tmp;
return true;
}
}
return false;
}

internal static bool TryRead(Sequence<RawResult> pairs, in CommandBytes key, ref int value)
{
long tmp = default;
if(TryRead(pairs, key, ref tmp)) {
value = checked((int)tmp);
return true;
}
return false;
}

internal static bool TryRead(Sequence<RawResult> pairs, in CommandBytes key, ref string value)
{
var len = pairs.Length / 2;
Expand Down

0 comments on commit 8b64a53

Please sign in to comment.