skip to Main Content

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


  1. 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.

    Login or Signup to reply.
  2. 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 like GEORADIUS 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 and SET timestamp:location 90 so it would be a two step query too.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search