Search code examples
redisdistancegeo

Redis. Distance between two members in different keys


I have two keys(geo zset) in redis first "DRIVERS" second "ORDERS" and members inside them. Is it possible to calculate distance between member in DRIVERS and member inside ORDERS? Manual https://redis.io/commands/geodist says that it is only possible between members in one key.


Solution

  • There's no built-in way to do that. However, You can try the following two solutions.

    1. Use GEOPOS command to get locations (longitude and latitude) of the driver and order. Then you can calculate the distance between them by yourself. Or you can put the results into a new GEOSET and let Redis do the calculation.
    2. Save both drivers and orders in the same GEOSET, e.g. GEOADD geo long1 lat1 driver:id, GEOADD geo long2 lat2 Order:id