Skip to content

Commit 7b3e8d1

Browse files
committed
fix parser for new reponse in FT.PROFILE redis#306
1 parent 2d5babb commit 7b3e8d1

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

src/NRedisStack/ResponseParser.cs

+8-1
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,14 @@ public static Dictionary<string, RedisResult> ToStringRedisResultDictionary(this
673673
foreach (var pair in res)
674674
{
675675
var arr = (RedisResult[])pair!;
676-
dict.Add(arr[0].ToString()!, arr[1]);
676+
if (arr.Length > 1)
677+
{
678+
dict.Add(arr[0].ToString()!, arr[1]);
679+
}
680+
else
681+
{
682+
dict.Add(arr[0].ToString()!, null);
683+
}
677684
}
678685
return dict;
679686
}

src/NRedisStack/Search/AggregationResult.cs

+4-3
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ internal AggregationResult(RedisResult result, long cursorId = -1)
1414
{
1515
var arr = (RedisResult[])result!;
1616

17-
// the first element is always the number of results
18-
TotalResults = (long)arr[0];
17+
// this statement below is not true as explained in the document https://redis.io/docs/latest/commands/ft.aggregate/#return
18+
// // the first element is always the number of results
19+
// TotalResults = (long)arr[0];
1920

2021
_results = new Dictionary<string, RedisValue>[arr.Length - 1];
2122
for (int i = 1; i < arr.Length; i++)
@@ -33,7 +34,7 @@ internal AggregationResult(RedisResult result, long cursorId = -1)
3334

3435
_results[i - 1] = cur;
3536
}
36-
37+
TotalResults = _results.Length;
3738
CursorId = cursorId;
3839
}
3940

tests/NRedisStack.Tests/Search/SearchTests.cs

+7-7
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ public void TestApplyAndFilterAggregations()
507507

508508
// actual search
509509
AggregationResult res = ft.Aggregate(index, r);
510-
Assert.Equal(3, res.TotalResults);
510+
Assert.Equal(2, res.TotalResults);
511511

512512
Row r1 = res.GetRow(0);
513513
Assert.Equal("def", r1.GetString("name"));
@@ -2685,7 +2685,7 @@ public void TestProfile()
26852685
var searchRes = profileSearch.Item1;
26862686
var searchDet = profileSearch.Item2;
26872687

2688-
Assert.Equal(5, searchDet.Count);
2688+
Assert.Equal(6, searchDet.Count);
26892689
Assert.Equal(2, searchRes.Documents.Count);
26902690

26912691

@@ -2694,8 +2694,8 @@ public void TestProfile()
26942694
var profileAggregate = ft.ProfileAggregate(index, aggReq);
26952695
var aggregateRes = profileAggregate.Item1;
26962696
var aggregateDet = profileAggregate.Item2;
2697-
Assert.Equal(5, aggregateDet.Count);
2698-
Assert.Equal(1, aggregateRes.TotalResults);
2697+
Assert.Equal(6, aggregateDet.Count);
2698+
Assert.Equal(2, aggregateRes.TotalResults);
26992699
}
27002700

27012701
[SkipIfRedis(Is.Enterprise)]
@@ -2715,16 +2715,16 @@ public async Task TestProfileAsync()
27152715
var searchRes = profileSearch.Item1;
27162716
var searchDet = profileSearch.Item2;
27172717

2718-
Assert.Equal(5, searchDet.Count);
2718+
Assert.Equal(6, searchDet.Count);
27192719
Assert.Equal(2, searchRes.Documents.Count);
27202720

27212721
// check using AggregationRequest
27222722
var aggReq = new AggregationRequest("*").Load(FieldName.Of("t")).Apply("startswith(@t, 'hel')", "prefix");
27232723
var profileAggregate = await ft.ProfileAggregateAsync(index, aggReq);
27242724
var aggregateRes = profileAggregate.Item1;
27252725
var aggregateDet = profileAggregate.Item2;
2726-
Assert.Equal(5, aggregateDet.Count);
2727-
Assert.Equal(1, aggregateRes.TotalResults);
2726+
Assert.Equal(6, aggregateDet.Count);
2727+
Assert.Equal(2, aggregateRes.TotalResults);
27282728
}
27292729

27302730
[Fact]

0 commit comments

Comments
 (0)