Search code examples
redisspring-data-redis

Redis georadius but with different sorting order


I am using redis to store and fetch interesting info around the user and show it as a feed.

Lets say I need to fetch all listings with in a given radius R (WITHDISTance) BUT sorted in a reverse chronological order and NOT by distance (as with redis GEORADIUS command). To be more specific, the most recent listing (with in radius R) should be at the top even though it is the farthest of all.

Is it somehow possible to do this with geoset alone ? Else how can I achieve this using some combo of redis datastructures ?

Looking for some clean and efficient approaches


Solution

  • You'll need to do the radius query and intersect the results with another Sorted Set that has the same elements but where the scores are timestamp. Then, page the resulting intersect in reverse order.