[Avg. reading time: 10 minutes]

Geospatial Index

Proximity Searches: These find items close to a given point, such as the nearest restaurants to a user's location.

Radius Queries: These queries retrieve items within a specific distance from a point. They are useful for services like delivery area checks or local event discovery.

Distance Calculation: Calculate the distance between two geo points.

GEOADD to add a point GEODIST to find the distance between two points GEOSEARCH to find all points within a radius

GEOADD locations -75.1118 39.7029 Glassboro 
GEOADD locations -75.2241 39.7393 MullicaHill
GEOADD locations -75.3105 39.7476 Swedesboro
GEOADD locations -75.2404259 39.8302 Paulsboro
GEOADD locations -75.0246 39.9268 CherryHill 
GEOADD locations -74.9489 39.9689 Moorestown 

## Straight Line or As-The-Crow-flies

GEODIST locations Glassboro MullicaHill mi
GEODIST locations CherryHill Moorestown mi
GEODIST locations CherryHill Moorestown km

## Find nearby areas

GEORADIUS locations -75.1118 39.7029 15 mi

GEOADD locations:restaurant -75.11486 39.72257 'Italian Affiar Restaurant'
GEOADD locations:restaurant -75.11275 39.70404 'LaScala Fire Glassboro'
GEOADD locations:restaurant -75.11333 39.70519 'Mexican Mariachi Grill'
GEOADD locations:pharmacy -75.13068 39.73228 'Pitman Pharmacy'
GEOADD locations:pharmacy -75.09853 39.68319 'Walgreens Pharmacy'

## Get nearby Restaurant & Pharmacy

GEORADIUS locations:restaurant -75.1118 39.7029 5 mi
GEORADIUS locations:pharmacy -75.1118 39.7029 2 mi

GEOSEARCH is same as GEORADIUS but cleaner syntax.

GEOSEARCH locations:cities FROMMEMBER Glassboro BYRADIUS 10 mi

GEOPOS locations:cities Moorestown

https://www.mapsofworld.com/usa/states/new-jersey/lat-long.html

Using GEOADD command to add geospatial data (latitude, longitude, and a member), Redis internally converts the latitude and longitude into a geohash. This geohash is then stored as the score in a sorted set, with the member name as the value. The sorted set allows for efficient querying of geospatial data, such as finding nearby locations.

GeoHash

Geohashing is a method of encoding geographic coordinates (latitude and longitude) into a compact string of letters and digits. This string represents a specific rectangular area on Earth, with higher precision obtained by increasing the length of the geohash. It essentially divides the world into a grid, with each geohash representing one of the grid cells.

Demonstrate how world is split into Grid :)

http://geohash.es

OR

https://geohash.softeng.co/

Search this place: dr49fg9q0hyx

GEOHASH locations CherryHill

Advantages

Proximity Search Optimization: Geohashes group nearby locations together by design. Locations with similar geohash prefixes are spatially close, allowing proximity searches to be performed more efficiently by simply comparing prefixes instead of calculating distances for every entry.

Efficient Indexing: Geohashes are simple alphanumeric strings that can be indexed using common database structures (like sorted sets or hash maps). This makes geohashes easier to index and search, reducing the complexity of querying nearby points.

Grid System for Clustering: The geohash grid system clusters nearby points by their geohash values. If you want to visualize or process areas in terms of spatial grids, geohashing provides a clean and efficient method of doing so.

Compact Representation: A geohash is a single compact alphanumeric string that represents both latitude and longitude in a single value. This saves space in databases and simplifies the process of querying and storing location data.

#redis #geospatialVer 5.5.3

Last change: 2025-10-15