Redis. Distance between two members in different keys

Viewed 1749

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.

3 Answers

GEODIST will only perform distance calculations between geospatial objects within the same Key. However, the backing store for Geospatial objects is a Sorted Set. Using ZUNIONSTORE the two sets can be combined, and the GEODIST can be performed on the resulting set.

> ZUNIONSTORE result 2 DRIVERS ORDERS aggregate min
> GEODIST result "driver_1" "order_1" km

Note: The aggregate min option is required, otherwise any elements that appear in more than one Set will have their scores aggregated. In the case of Geospatial data, this would cause the point to move its Longtitude and Latitude position.

Related