darshan kamat
darshan kamat

Reputation: 424

Pagination in No-sql database

Does no SQL database's like Redis support pagination feature. Use case : I have whole of customer data in Redis instance.However for my API ,request will be coming with pagination (eg :with paging size 10), now i need to load all of the data(lets say -10000) in my Application(Spring boot) from Redis and then do the pagination and return the relevant records(only 10). However for SQL database's like Oracle it is much easier with functions like Rownum which help to do the pagination at the DB level itself and this extra logic is not needed in the application code . Is there any workaround or better way in No-SQL DB's like Redis to do the same

Upvotes: 1

Views: 1171

Answers (1)

anL
anL

Reputation: 1073

Keep your customer data at a Sorted Set in Redis. Sorted sets provide great features to sort data and requesting them between an interval.

Lets say, your data is loaded to a sorted set with their IDs. If you need to get 10 customer per page, just call the following for each page:

ZRANGE yourcustomerset 0 9
ZRANGE yourcustomerset 10 19
ZRANGE yourcustomerset 20 29

Please check this too

Upvotes: 2

Related Questions