Advertisement
Beginner Redis, Geospatial Data in Redis

How do you find the distance between two stored locations in Redis?

Short answer

You use the GEODIST command, specifying the two member names whose distance you want to calculate along with an optional unit like meters, kilometers, or miles, and Redis returns the calculated distance between those two points based on their stored geographic coordinates.

Save Redis mock interview
Advertisement
AModel answer
You use the GEODIST command, specifying the two member names whose distance you want to calculate along with an optional unit like meters, kilometers, or miles, and Redis returns the calculated distance between those two points based on their stored geographic coordinates.
Example

GEODIST locations 'San Francisco' 'New York' km

Real-world example
A travel planning application calculates the distance between two cities a user has selected, using GEODIST to instantly return the distance in kilometers without needing a separate geographic calculation service.
Likely follow-ups
  • What units does GEODIST support besides kilometers?
  • How accurate is the distance calculation compared to a dedicated mapping service?
Related topics