Skip to content

Commit 27edd7b

Browse files
authored
setting internal cursor to 0 when no cursor is called for (#462)
1 parent d2647d6 commit 27edd7b

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

src/Redis.OM/Aggregation/AggregationEnumerator.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ internal AggregationEnumerator(Expression exp, IRedisConnection connection, int
3939
_aggregation = ExpressionTranslator.BuildAggregationFromExpression(exp, typeof(T));
4040
_connection = connection;
4141
_useCursor = useCursor;
42+
if (!_useCursor)
43+
{
44+
_cursor = 0;
45+
}
4246
}
4347

4448
/// <summary>
@@ -164,7 +168,11 @@ public async ValueTask<bool> MoveNextAsync()
164168
/// <inheritdoc/>
165169
public void Reset()
166170
{
167-
_cursor = -1;
171+
if (_useCursor)
172+
{
173+
_cursor = -1;
174+
}
175+
168176
_index = 0;
169177
_chunk = Array.Empty<AggregationResult<T>>();
170178
}

test/Redis.OM.Unit.Tests/RediSearchTests/AggregationSetTests.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,24 @@ RedisReply MockedResult
3131
}
3232
}
3333

34+
RedisReply MockedResultWithoutCursor
35+
{
36+
get
37+
{
38+
var replyList = new List<RedisReply>();
39+
replyList.Add(new RedisReply(1));
40+
for(var i = 0; i < 1000; i++)
41+
{
42+
replyList.Add(new RedisReply(new RedisReply[]
43+
{
44+
$"FakeResult",
45+
"blah"
46+
}));
47+
}
48+
return replyList.ToArray();
49+
}
50+
}
51+
3452
RedisReply MockedResultCursorEnd
3553
{
3654
get
@@ -629,5 +647,17 @@ public void TestMultiPredicateFilter()
629647
_ = collection.Filter(query).ToList();
630648
_substitute.Received().Execute("FT.AGGREGATE", "person-idx", "*", "FILTER", "@TagField == 'foo' && @Address_State == 'FL'", "WITHCURSOR", "COUNT", "10000");
631649
}
650+
651+
[Fact]
652+
public async Task TestNoCursorDelete()
653+
{
654+
var collection = new RedisAggregationSet<Person>(_substitute);
655+
_substitute.ExecuteAsync("FT.AGGREGATE", Arg.Any<object[]>()).Returns(MockedResultWithoutCursor);
656+
657+
Expression<Func<AggregationResult<Person>, bool>> query = a => a.RecordShell!.TagField == "foo" && a.RecordShell.Address.State == "FL";
658+
_ = await collection.Filter(query).ToListAsync();
659+
await _substitute.Received().ExecuteAsync("FT.AGGREGATE", "person-idx", "*", "FILTER", "@TagField == 'foo' && @Address_State == 'FL'");
660+
await _substitute.DidNotReceive().ExecuteAsync("FT.CURSOR", Arg.Any<object[]>());
661+
}
632662
}
633663
}

0 commit comments

Comments
 (0)