'Redis storing and getting multiple records

I'm quite new to redis and have a task at hand to optimize redis operations for a dashboard of a non-profit.

The scenario:

  • We have multiple cities (London, Rome,...)
  • We have 1000s of users in each city

We have a need to load users from a particular city, and at the moment it is stored by city ID. As you can imagine, this results in a massive document that needs to be re-cached on every small change to the user.

I want to change this methodology so users are stored in Redis in the following format: [cityID][userID]. So if I need to pull all users from london, I can just call IDFORLONDON?

Would this be the correct way to approach it? Is there a way to load only 10 users from IDFORLONDON? (for pagination). Or is my option to load all and then slice?

Thank you!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source