Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Geo-redis, store additional data

Tags:

redis

I'm using the Redis Geo API to store positions, then i fetch them with GEORADIUS. Since i can only set latitude, longitude and a name for each location, how i can store and retrieve other data when i fetch locations with GEORADIUS?

First thing that come in my mind was to use GEOADD name as a key, and then store additional data in a normal key/value set, with the key being the same as name, fetch the array of positions with GEORADIUS, and loop trough that array and fetch other data using name as key.

Is this the correct approach or there is a better way to do that?

like image 285
Fr0z3n Avatar asked Sep 05 '26 17:09

Fr0z3n


1 Answers

If the other data needs to be updated/accessed, storing it in a different key (usually a Hash) makes sense. However, if the other data per name is immutable and accessed only in conjugation to the geo querying, you can just "embed" it after the name, e.g.:

GEOADD geoset lon lat name:data1:data2:...:datan

Of course, when getting the query's reply you'll have to "decode" the results and break each one back into its constituting components.

like image 62
Itamar Haber Avatar answered Sep 07 '26 08:09

Itamar Haber



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!