Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set expire when using Redis geoadd

I am using the new geospatial features on Redis. I know that behind the scene it's using ZSET.

I am adding new entries this way:

GEOADD" "report-geo-set" "4.78335244" "32.07223969" "jossef"

How could I add an expire to a specific records(in my case: "jossef")

on my set?

If the API doesnt provide it is there any workaround for this?

Thanks, ray.

like image 901
rayman Avatar asked Oct 18 '15 09:10

rayman


1 Answers

Regrettably no - Redis expires entire keys and not the values in their respective data structures. Geo Hashes are implemented on top Sorted Sets and expiration of individual members isn't supported.

What you could do is maintain an additional Sorted Set and for each member in it store the expiration timestamp as score. Then, periodically, fetch the members that need to be expired from it based on ZRANGEBYSCORE and "manually" ZREM the respective members from your Geo Hash.

like image 171
Itamar Haber Avatar answered Sep 19 '22 05:09

Itamar Haber