Skip to content

Commit

Permalink
setting internal cursor to 0 when no cursor is called for (#462)
Browse files Browse the repository at this point in the history
  • Loading branch information
slorello89 committed Jul 15, 2024
1 parent d2647d6 commit 27edd7b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
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[]>());
}
}
}

0 comments on commit 27edd7b

Please sign in to comment.