Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement KeyValuePairParser.TryRead for Int64 #1568

Merged
merged 1 commit into from
Sep 10, 2020
Merged
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
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