GEOADD-&-GEODIST
Store latitude/longitude data and find nearby locations. Perfect for store finders, delivery apps, and location-based features.
You'll Learn
- GEOADD for storing coordinates
- GEODIST for calculating distances
- GEOSEARCH for finding nearby items
- How Redimo displays geo data
See Your Data, Not Terminal Text
Redimo visualizes every Redis data type beautifully. Edit inline, undo mistakes, stay safe in production.
1. What Are Geo Commands?
Geo commands let you store locations (longitude, latitude) and perform spatial queries like "find all stores within 10km." Under the hood, Redis uses a Sorted Set with geohash-encoded scores for efficient querying.
This means all Sorted Set commands (ZRANGE, ZREM, ZSCORE) also work on geo data. The "score" is the geohash, a clever encoding that maps 2D coordinates to a 1D number while preserving proximity.
Syntax
GEOADD key longitude latitude member [lon lat member ...]
GEODIST key member1 member2 [unit] # unit: m, km, mi, ft
GEOPOS key member [member ...] # Get coordinates
GEOSEARCH key FROMMEMBER member BYRADIUS radius unit
GEOSEARCH key FROMLONLAT lon lat BYRADIUS radius unit
GEOSEARCH key FROMLONLAT lon lat BYBOX width height unit
GEOHASH key member [member ...] # Get geohash stringDistance Units
m- meters (default)km- kilometersmi- milesft- feet
Common Use Cases
- • Store/restaurant finders
- • Delivery radius checks
- • Nearby user matching
- • Geofencing alerts
2. The CLI Way (Hard Mode)
Adding locations and finding nearby places in CLI means typing coordinates carefully and parsing raw output:
Adding Locations
127.0.0.1:6379> GEOADD stores:coffee -73.985428 40.748817 "empire-state"
(integer) 1
127.0.0.1:6379> GEOADD stores:coffee -73.968285 40.785091 "central-park"
(integer) 1
127.0.0.1:6379> GEOADD stores:coffee -74.044500 40.689247 "statue-liberty"
(integer) 1
127.0.0.1:6379> GEOADD stores:coffee -73.989308 40.757988 "times-square"
(integer) 1Querying Geo Data
127.0.0.1:6379> GEODIST stores:coffee "empire-state" "central-park" km
"4.1543"
127.0.0.1:6379> GEOPOS stores:coffee "empire-state"
1) 1) "-73.98542732000351"
2) "40.74881653388516"
127.0.0.1:6379> GEOSEARCH stores:coffee FROMMEMBER "empire-state" BYRADIUS 5 km
1) "empire-state"
2) "times-square"
3) "central-park"
127.0.0.1:6379> GEOSEARCH stores:coffee FROMLONLAT -73.98 40.75 BYRADIUS 5 km WITHDIST
1) 1) "empire-state"
2) "0.5234"
2) 1) "times-square"
2) "1.0023"
3) 1) "central-park"
2) "3.9876"The Problem
3. The Redimo Way (Smart Mode)
Redimo recognizes Geo data (it's a ZSet internally) and displays coordinates clearly. Each member shows its latitude and longitude in a readable format. Since it's a Sorted Set, all ZSet features work too.
What Redimo Does for Geo Data:
- ●Clear Coordinate Display: Each member shows both member name and its decoded coordinates, not just the geohash score.
- ●ZSet Compatibility: Since Geo uses Sorted Sets, all ZSET features work - sorting, filtering, range queries.
- ●Inline Editing: Edit member names or remove locations with standard ZSet controls.
- ●Member Count: See total location count at a glance.
CLI Pain Points
- • Raw coordinate numbers
- • No visual verification
- • Easy to swap lon/lat
- • Geohash scores are unreadable
- • No spatial context
Redimo Solutions
- • Clear member + coordinates
- • Decoded coordinate display
- • ZSet features all work
- • Inline coordinate editing
- • Member management UI
4. Common Geo Patterns
Store Finder
# Add store locations
GEOADD stores:pizza -122.4194 37.7749 "sf-downtown"
GEOADD stores:pizza -122.4094 37.7849 "sf-soma"
GEOADD stores:pizza -122.3994 37.7649 "sf-mission"
# Find stores within 2km of user's location
GEOSEARCH stores:pizza FROMLONLAT -122.41 37.78 BYRADIUS 2 km
# With distances
GEOSEARCH stores:pizza FROMLONLAT -122.41 37.78 BYRADIUS 2 km WITHDIST WITHCOORD
# Sort by distance (ASC = closest first)
GEOSEARCH stores:pizza FROMLONLAT -122.41 37.78 BYRADIUS 5 km ASC COUNT 5Delivery Zone Check
# Define delivery hub
GEOADD delivery:hubs -73.985 40.748 "hub-manhattan"
# Check if customer is within delivery radius
# Returns distance - if nil, member doesn't exist
GEODIST delivery:hubs "hub-manhattan" "customer:123" km
# If distance > max_radius, reject order
# Alternative: add customer temporarily, search, remove
GEOADD delivery:temp -73.990 40.750 "customer:123"
GEOSEARCH delivery:temp FROMMEMBER "customer:123" BYRADIUS 5 km
ZREM delivery:temp "customer:123"Nearby Users
# Update user location on GPS ping
GEOADD users:active -122.4194 37.7749 "user:1001"
# Find users near current user
GEOSEARCH users:active FROMMEMBER "user:1001" BYRADIUS 1 km WITHDIST
# Find users in a rectangular area (city block)
GEOSEARCH users:active FROMLONLAT -122.42 37.78 BYBOX 500 500 m5. Understanding Geohash
Geo commands work because of geohashing - encoding 2D coordinates into a 1D value that preserves proximity:
What is a Geohash?
A geohash divides the Earth into a grid and encodes each cell as a string. Nearby locations share common prefixes. "sqc8b49rny0" and "sqc8b49rny1" are close together.
How Redis Uses It
Redis converts the geohash to a 52-bit integer and stores it as the Sorted Set score. This allows range queries to efficiently find nearby points.
Precision Trade-offs
Redis uses 52-bit precision, giving ~0.6mm accuracy. More than enough for any real-world application. The geohash string is 11 characters.
Working with Geohash
# Get geohash string (useful for debugging)
GEOHASH stores:coffee "empire-state"
# Returns: "dr5ru6j8862"
# Geohash prefixes indicate proximity
# dr5ru... locations are all in the same area
# You can use geohash in external tools
# Many mapping services accept geohash strings6. Pro Tips
Coordinate Order: Longitude First!
GEOSEARCH Options (Redis 6.2+)
# Search by radius from coordinates
GEOSEARCH key FROMLONLAT -122.4 37.8 BYRADIUS 10 km
# Search by radius from existing member
GEOSEARCH key FROMMEMBER "store:1" BYRADIUS 5 mi
# Search by bounding box
GEOSEARCH key FROMLONLAT -122.4 37.8 BYBOX 10 10 km
# Add options
GEOSEARCH key FROMLONLAT -122.4 37.8 BYRADIUS 10 km \
WITHDIST \ # Include distance
WITHCOORD \ # Include coordinates
WITHHASH \ # Include geohash
ASC \ # Sort by distance (ascending)
COUNT 10 # Limit resultsGEORADIUS vs GEOSEARCH
Redimo Bonus
Ready to Map?
Stop guessing if your coordinates are correct.
Download Redimo and manage geo data visually.