Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
198 views
in Technique[技术] by (71.8m points)

design patterns - Redis and MySQL Pagination Strategy

I'm trying to return a list of recent items and have simple pagination. What I'm first doing is making this query

SELECT * FROM table ORDER BY time LIMIT 300;

Then I'm caching it into a Redis sorted set with time as the score. This allows me to paginate efficiently (about 25 a page). What I'm stuck on is what do I do if some user actually reaches the end. Do I just make a massive initial query? Or do I make another query like this when they reach the end.

SELECT * FROM table WHERE time < last_item_time ORDER BY time LIMIT 300;

For the latter strategy, it seems I would have to keep track of the latest item time in the user session key in Redis which is doable but a little annoying. Wondering if there's a better approach since I'm new to backend.

question from:https://stackoverflow.com/questions/66057461/redis-and-mysql-pagination-strategy

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...