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

setting internal cursor to 0 when no cursor is called for #462

Merged
merged 1 commit into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
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
10 changes: 9 additions & 1 deletion src/Redis.OM/Aggregation/AggregationEnumerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ internal AggregationEnumerator(Expression exp, IRedisConnection connection, int
_aggregation = ExpressionTranslator.BuildAggregationFromExpression(exp, typeof(T));
_connection = connection;
_useCursor = useCursor;
if (!_useCursor)
{
_cursor = 0;
}
}

/// <summary>
Expand Down Expand Up @@ -164,7 +168,11 @@ public async ValueTask<bool> MoveNextAsync()
/// <inheritdoc/>
public void Reset()
{
_cursor = -1;
if (_useCursor)
{
_cursor = -1;
}

_index = 0;
_chunk = Array.Empty<AggregationResult<T>>();
}
Expand Down
30 changes: 30 additions & 0 deletions test/Redis.OM.Unit.Tests/RediSearchTests/AggregationSetTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,24 @@ RedisReply MockedResult
}
}

RedisReply MockedResultWithoutCursor
{
get
{
var replyList = new List<RedisReply>();
replyList.Add(new RedisReply(1));
for(var i = 0; i < 1000; i++)
{
replyList.Add(new RedisReply(new RedisReply[]
{
$"FakeResult",
"blah"
}));
}
return replyList.ToArray();
}
}

RedisReply MockedResultCursorEnd
{
get
Expand Down Expand Up @@ -629,5 +647,17 @@ public void TestMultiPredicateFilter()
_ = collection.Filter(query).ToList();
_substitute.Received().Execute("FT.AGGREGATE", "person-idx", "*", "FILTER", "@TagField == 'foo' && @Address_State == 'FL'", "WITHCURSOR", "COUNT", "10000");
}

[Fact]
public async Task TestNoCursorDelete()
{
var collection = new RedisAggregationSet<Person>(_substitute);
_substitute.ExecuteAsync("FT.AGGREGATE", Arg.Any<object[]>()).Returns(MockedResultWithoutCursor);

Expression<Func<AggregationResult<Person>, bool>> query = a => a.RecordShell!.TagField == "foo" && a.RecordShell.Address.State == "FL";
_ = await collection.Filter(query).ToListAsync();
await _substitute.Received().ExecuteAsync("FT.AGGREGATE", "person-idx", "*", "FILTER", "@TagField == 'foo' && @Address_State == 'FL'");
await _substitute.DidNotReceive().ExecuteAsync("FT.CURSOR", Arg.Any<object[]>());
}
}
}
Loading