redis / redis-om-dotnet

Object mapping, and more, for Redis and .NET
MIT License
457 stars 76 forks source link

How to achieve pagination, limit & offset via Redis and not Linq/C#? #282

Closed JuliusMikkela closed 1 year ago

JuliusMikkela commented 1 year ago

Hi, just getting started with Redis OM, and while I can get most things working as I want I've yet to figure out how to achieve pagination or limit/offset of queried data via Redis instead of relying on Linq of the result. Ideally what I'd like to do is the same effect as specifying "limit x y" would in ft.search, i.e.: "FT.SEARCH idx:myindex * limit 50000 10000"

Is this at all possible, or is the currently intended approach to load the full result into C# and do pagination from there? Feels like a bit of lost performance in making C# do what I assume Redisearch does better?

slorello89 commented 1 year ago

Use Skip/Take

JuliusMikkela commented 1 year ago

You mean the IQueryable Skip/Take?

Like this one:

IRedisCollection<T> 
   .AsQueryable()
   .OrderBy(x => x.MyValue)
   .Skip(50000)
   .Take(10000)
   .AsRedisCollection()
   .ToListAsync();

Will that actually do the work Redis-side? If so, that's quite neat, and maybe this could be added to the ReadMe to clarify?

slorello89 commented 1 year ago

You shouldn't need the AsQueryable/AsRedisCollection but yes

JuliusMikkela commented 1 year ago

Fair enough, in that case I'm all set. Thanks for the quick reply, and happy holidays!