redis-om-python icon indicating copy to clipboard operation
redis-om-python copied to clipboard

Add a `page` function for `find`

Open simonprickett opened this issue 3 years ago • 4 comments

Allow the user to page through all results rather than returning them all in one go... .find().page(offset, limit). See Redis OM Node for a good example.

simonprickett avatar Jun 27 '22 17:06 simonprickett

In the meantime, FindQuery(expressions=[], model=self.model, offset=skip, limit=limit).execute() works for me

mpmX avatar Jun 28 '22 13:06 mpmX

In the meantime, FindQuery(expressions=[], model=self.model, offset=skip, limit=limit).execute() works for me

How do I use this? Can you put up an example code snippet?

iamvishalkhare avatar Jul 13 '22 19:07 iamvishalkhare

How do I use this? Can you put up an example code snippet?

Assuming your model class is called Entity:

from redis_om import FindQuery
expressions = [(Entity.some_attribute == 1)]
skip = 10
limit = 10
result = FindQuery(expressions=expressions, model=Entity, offset=skip, limit=limit).execute()

mpmX avatar Jul 20 '22 15:07 mpmX

Current functionality of the execution of queries appends all results together - https://github.com/redis/redis-om-python/blob/dcd84e0ab2686a3c6ff7f6c6a43ec49f4b65655f/aredis_om/model/model.py#L740

This change will require changing how results are returned to users, not just adding a function. Closed the draft PR I had for this after realizing the above.

sav-norem avatar Aug 04 '22 12:08 sav-norem

@simonprickett - wiseaidev implemented this how it's described so I think we should go ahead and close this

sav-norem avatar Sep 07 '22 15:09 sav-norem