How to optimizing database queries

How can I optimize an API, starting with optimizing database queries?

Step 1: Model.objects.filter(is_disabled=0)

Step 2: Index the database

Step 3: Use pagination: Model.objects.filter(is_disabled=0)[offset:offset+10], where offset depends on the page number.

Step 4: Consider using Redis to save data. Which Redis method should I use? I feel that a sorted set is fast, but it only stores integers and strings. If I want to save a dictionary, I need to use another Redis method. I'm also facing an issue with the Redis key if add data in redis for (Model.objects.filter(is_disabled=0)[offset:offset+10]) then key should be redis_key=”key”+str(page_number)), as deleting data would affect all page numbers. How can I handle Redis keys with page numbers?

is it Good or bad to use redis for every 10 rows?

Back to Top