StackExchange / StackExchange.Redis

General purpose redis client
https://stackexchange.github.io/StackExchange.Redis/
Other
5.86k stars 1.5k forks source link

SetScan returns the number of errors, and pageSize is invalid #2574

Closed guaicaiboshi closed 9 months ago

guaicaiboshi commented 9 months ago

I expected to pageSize to return the number of entries, but it failed image

mgravell commented 9 months ago

Right. That is indeed not what that property means. Rather, that simply stores the passed in paging hint used on the API, but this is not a hard rule (hence "hint") - the server gives whatever it wants per page, which can be zero or higher than the hint.

mgravell commented 9 months ago

Also, you've done a ToArray() on the result, which will enumerate all pages and give you everything. The page parameters here impact what happens in the background - but changing the page size shouldn't change that you get all records back. That again : is not what that is intended to do.

If you're after the first N records: perhaps use the LINQ method .Take(N). Because of how SE.Redis scanning works, this will be done efficiently (it won't fetch everything then discard most of it)

guaicaiboshi commented 9 months ago

Also, you've done a ToArray() on the result, which will enumerate all pages and give you everything. The page parameters here impact what happens in the background - but changing the page size shouldn't change that you get all records back. That again : is not what that is intended to do.

If you're after the first N records: perhaps use the LINQ method .Take(N). Because of how SE.Redis scanning works, this will be done efficiently (it won't fetch everything then discard most of it)

Thank you very much, the LINQ method .Take(N) works perfectly.