0

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

Vijith
  • 77
  • 1
  • 10

1 Answers1

1

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.

Itamar Haber
  • 47,336
  • 7
  • 91
  • 117
  • Thanks. Did think of this approach but how do I maintain the distance information ? I know GEORADIUS has a STOREDIST option to store the distance in a separate ZSET, but I will have to fetch that info for each of the elements in the page. Is there a easier or better way of maintaining the distance info as well – Vijith Aug 01 '17 at 08:10
  • Nope - you'll have to store one datum in the zset, and fetch the other – Itamar Haber Aug 01 '17 at 08:45