Reputation: 159
I'm trying to sort a bunch of data that I get from georadius to be sorted reverse-chronologically based on when the data gets posted. So if I post item1, item3, item2, item4 and they're all within range of the georadius command it should return item4, item2, item3, and item1 regardless of distance. How would I do this with redis's geospatial commands? Thanks!
Upvotes: 1
Views: 436
Reputation: 22926
First of all, you need to save the post time of each item. For example, you can set a key-value pair for each item, with key as item name, and value as post time.
When you post an item, add it into the GEO structure with geo info, and also record the post time:
GEOADD geo lng lat item1
SET posttime:item1 timestamp-in-seconds
When you want to do a search, take the following steps:
GEORADIOUS
command with STORE
option to save the result into a sorted set. Let's name the sorted set as temp result.SORT
command to sort temp result with post time: SORT temp_result BY posttime:* DESC
Upvotes: 3