My aim is to create a cache of road speed limits on Redis (taken from OSM) where searching the position with latitude and longitude, returns the speed limit in a certain radius using GEORADIUS.
The problem is that using:
GEOADD speed-limits -45.000000 10.000000 "90"
if I add a new position with always the limit of 90 the previous one is overwritten.
2
Answers
Yes. It would get overwritten because
90
is already assigned a value.Generally, you need to choose your keys carefully. Instead of simply storing the speed-limit, you can multiple delimiters such as timestamps,random-hashes or even some other useful information (say city) in this case with the limit.
For example, "90" could be transformed to
90#1606757564#abcde#city_name
.This way, when you query for the radius, you would get the entire key. Use a simple
startsWith()
check to get the original limit.You can either
(1) use a compound key as the member
so it is
GEOADD speed-limits -45.000000 10.000000 90:timestamp:location
, and the query would be something likeGEORADIUS speed-limits ... WITHCOORD
and then use.split(":")[0]
to get the speed.or
(2) store the speed separately
GEOADD speed-limits -45.000000 10.000000 timestamp:location
andSET timestamp:location 90
so it would be a two step query too.