0
0
Redisquery~30 mins

Geo-proximity with sorted sets in Redis - Mini Project: Build & Apply

Choose your learning style9 modes available
Geo-proximity with sorted sets
📖 Scenario: You are building a simple location-based service that stores places with their geographic coordinates. You want to find places near a specific location.
🎯 Goal: Create a Redis sorted set to store places with their longitude and latitude. Then, configure a radius distance. Next, query the sorted set to find places within that radius sorted by distance. Finally, complete the setup to return the results with distances.
📋 What You'll Learn
Create a sorted set called places with three places and their longitude and latitude using GEOADD.
Create a variable radius set to 10 kilometers.
Use GEORADIUS command on places with center longitude 13.361389 and latitude 38.115556, radius radius, unit km, and sort results by distance ascending.
Add the option to return distances with the results.
💡 Why This Matters
🌍 Real World
Location-based services like finding nearby restaurants, stores, or landmarks use geo-proximity queries to provide relevant results to users.
💼 Career
Understanding Redis geo commands is useful for backend developers working on location-aware applications, improving user experience with fast and efficient geographic queries.
Progress0 / 4 steps
1
Create the sorted set with places
Use the GEOADD command to add these three places to a sorted set called places with their exact longitude and latitude: Palermo (13.361389, 38.115556), Catania (15.087269, 37.502669), and Messina (15.550000, 38.193000).
Redis
Need a hint?

Use GEOADD places longitude latitude member format for each place.

2
Set the radius variable
Create a variable called radius and set it to 10 to represent 10 kilometers.
Redis
Need a hint?

Use SET radius 10 to create the variable.

3
Query places within radius sorted by distance
Use the GEORADIUS command on places with center longitude 13.361389 and latitude 38.115556, radius radius, unit km, and sort the results by distance ascending using ASC.
Redis
Need a hint?

Use GEORADIUS places longitude latitude radius km ASC to get sorted results.

4
Return distances with the results
Add the WITHDIST option to the GEORADIUS command to return the distances along with the place names.
Redis
Need a hint?

Add WITHDIST after ASC in the GEORADIUS command.