How do you find all stored locations within a certain radius of a specific point using Redis?
Short answer
You use the GEOSEARCH command, specifying a center point either by coordinates or by an existing member's name, along with a radius and unit, and Redis returns all members within that stored dataset that fall within the specified distance from the center point.
Advertisement
AModel answer
You use the GEOSEARCH command, specifying a center point either by coordinates or by an existing member's name, along with a radius and unit, and Redis returns all members within that stored dataset that fall within the specified distance from the center point.
Example
GEOSEARCH locations FROMMEMBER 'San Francisco' BYRADIUS 500 km ASC
Real-world example
A ride sharing application finds all available drivers within a five kilometer radius of a customer's pickup location using GEOSEARCH, quickly identifying the nearest available options.
Likely follow-ups
- What is the difference between searching from a member versus searching from specific coordinates?
- Can GEOSEARCH also search within a rectangular area instead of a radius?
Related topics