This repository provides some exercises around Redis commands that are related to geospatial search.
This repository is just sharing the exercises of the 'Geolocation-Aware Applications with Redis' training. The learning objectives of the entire training are:
- Know how Geo-aware solutions are used and which problems are addressed by them
- Understand and be able to present the technology basics
- Understand the technical details of the Redis Geo* commands and their approach to support geo-spatial use cases
- Understand the data modeling basics
- Get insights how geo-spatial solutions are implemented with traditional vendors
- Know where to find additional resources about how to implement location-aware applications with Redis
- Ensure that your computer is connected to the internet as your computer will need to access some external resources (e.g., CCS files & JavaScript UI libraries)
- Prepare a Python 3.x development environment! The Python dependencies need to be installed:
- Flask
- Redis
cd geoapp pip install virtualenv virtualenv --python=python3 geoappvenv source geoappvenv/bin/activate pip install -r requirements.txt python --version
- Please install Redis 6 OSS locally!
- No additional Redis module is required for this exercise.
- Clone the following code repository locally: https://github.com/redislabs-training/training-geo-public !
- This results in a local working copy of the source code.
- Please don’t publish the source code (e.g., by forking and pushing to a public Git repo)!
- Configure the application to use your Redis database via the file ‘config.py’!
- The default configuration uses port 6379.
- Verify the database connectivity!
- Change the directory to the source code directory ‘geoapp’!
- Take a look at the Python script ‘importer.py’!
- Run the Python script ‘importer.py’ via
python importer.py
! - Wait until the import completes. The importer shows the message ‘Import of 16790 records completed’.
- Which steps could be performed to speed the import up?
- Open the file ‘app.py’ with an editor of your choice!
- Read and understand the source code!
- The file is just 125 lines of code long.
The idea of this exercise is to complete 5 simple implementation tasks. The surrounding source code is given, which should allow you to focus on the Redis commands. Each task is marked within the source code (e.g., # Task 1 … <Your code here!>
).
- You will need to identify the relevant index within the database. Indexes are prefixed with ‘idx’.
- Please assign the result of the command to the variable ‘rs’! This variable should have the type of an ‘iterator’. The Redis-side cursor-based iteration is already implemented by the client library.
- The country should be retrieved as a Python string value, and it should be assigned to the variable with the name ‘country’.
- You can verify if Task 1 and Task 2 returned a valid result by looking at the debug output:
DEBUG: id = {}, city = {}, country = {}
- You will need to identify the index within the database, which holds the geo-coordinates of cities.
- The result of the command should be assigned to the variable ‘pos’
- The previously fetched city coordinates can be leveraged for finding close-by breweries.
- You will also need to use the distance variable (dist), which was passed over as a request parameter. The distance is considered to be in miles.
- Please construct your command in a way that ...
- You are NOT fetching the exact distance of resulting brewery.
- You are fetching the coordinates of a resulting brewery.
- A maximum of 10 breweries are returned (it might be otherwise hard to draw more than 10 on a map).
- The result-set should be assigned to the variable ‘brewcoords’.
- The details which we retrieved in step 4 are limited to the data which was stored within the index. Please retrieve the following additional brewery details from the database!
- Name
- City
- The result of the command is a dictionary that has the properties ‘name’ and ‘city’. The variable name for this dictionary should be ‘b’.
- You can verify if Task 3 to 5 were completed successfully by taking a look at the debug output:
DEBUG: breweries = {}
- Change the directory to the source code directory ‘geoapp’!
- Run the command
python app.py
- The application listens on port 5500, so you will be able to reach it via http://localhost:5500
- It’s expected to see the following:
- Click on the link ‘Test DB Connectivity’. The expected result is:
- Click on the link ‘Home’ to return to the start page again!
- Fill the form in with the following details and then press the ‘Submit’ button:
- City: New York
- Distance: 50 miles
- Congrats! You completed the implementation exercise successfully if you are seeing the following output: